[PATCH] v4l: tuner improvements

*tuner-core.c:
- some tuner_info msgs will be generated only if insmod opt
tuner_debug enabled.
- Implemented tuner-core support for VIDIO_S_TUNER to allow
changing mono/stereo mode
- Remove unneeded config options.
- I2C_CLIENT_MULTI option removed.
- support for Philips FMD12ME hybrid tuner
- allow to initialize with another tuner
- Move PHILIPS_FMD initialization code to set_type function,

* tda8290:

- Fix dumb error in tda8290 tunning.
- Radio tuner uses high-precision step instead of 62.5 KHz.

*tea5767.c:
- tuner_info msgs will be generated only if insmod tuner option
tuner_debug enabled.
- some cleanups for better reading.
- Radio tuner uses high-precision step instead of 62.5 KHz.
- Changing radio mode stereo/mono for tea5767 working.

*tuner-simple.c:
- TNF9533-D/IF UHF fixup.
- Radio tuners now uses high-precision step instead of 62.5 KHz.

*mt20xx.c:
- Radio tuner uses high-precision step instead of 62.5 KHz.

*tda9887.c:
- tab and blank spaces corrections.

Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
Signed-off-by: Gerd Knorr <kraxel@bytesex.org>
Signed-off-by: Nickolay V Shmyrev <nshmyrev@yandex.ru>
Signed-off-by: Hartmut Hackmann <hartmut.hackmann@t-online.de>
Signed-off-by: Michael Krufky <mkrufky@m1k.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Mauro Carvalho Chehab and committed by Linus Torvalds 586b0cab 96b6aba0

+471 -116
+1 -2
drivers/media/video/Makefile
··· 7 7 zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 8 8 zr36067-objs := zoran_procfs.o zoran_device.o \ 9 9 zoran_driver.o zoran_card.o 10 - tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o 11 - 10 + tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o 12 11 obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o 13 12 14 13 obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \
+3 -3
drivers/media/video/mt20xx.c
··· 1 1 /* 2 - * $Id: mt20xx.c,v 1.4 2005/03/04 09:24:56 kraxel Exp $ 2 + * $Id: mt20xx.c,v 1.5 2005/06/16 08:29:49 nsh Exp $ 3 3 * 4 4 * i2c tv tuner chip device driver 5 5 * controls microtune tuners, mt2032 + mt2050 at the moment. ··· 295 295 int if2 = t->radio_if2; 296 296 297 297 // per Manual for FM tuning: first if center freq. 1085 MHz 298 - mt2032_set_if_freq(c, freq*62500 /* freq*1000*1000/16 */, 299 - 1085*1000*1000,if2,if2,if2); 298 + mt2032_set_if_freq(c, freq * 1000 / 16, 299 + 1085*1000*1000,if2,if2,if2); 300 300 } 301 301 302 302 // Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
+14 -6
drivers/media/video/tda8290.c
··· 1 1 /* 2 - * $Id: tda8290.c,v 1.7 2005/03/07 12:01:51 kraxel Exp $ 2 + * $Id: tda8290.c,v 1.11 2005/06/18 06:09:06 nsh Exp $ 3 3 * 4 4 * i2c tv tuner chip device driver 5 5 * controls the philips tda8290+75 tuner chip combo. ··· 69 69 static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 }; 70 70 static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 }; 71 71 static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00, 72 - 0x7C, 0x04, 0xA3, 0x3F, 72 + 0xfC, 0x04, 0xA3, 0x3F, 73 73 0x2A, 0x04, 0xFF, 0x00, 74 74 0x00, 0x40 }; 75 75 static unsigned char i2c_set_VS[2] = { 0x30, 0x6F }; ··· 138 138 139 139 static void set_frequency(struct tuner *t, u16 ifc) 140 140 { 141 - u32 N = (((t->freq<<3)+ifc)&0x3fffc); 141 + u32 freq; 142 + u32 N; 142 143 143 - N = N >> get_freq_entry(div_table, t->freq); 144 + if (t->mode == V4L2_TUNER_RADIO) 145 + freq = t->freq / 1000; 146 + else 147 + freq = t->freq; 148 + 149 + N = (((freq<<3)+ifc)&0x3fffc); 150 + 151 + N = N >> get_freq_entry(div_table, freq); 144 152 t->i2c_set_freq[0] = 0; 145 153 t->i2c_set_freq[1] = (unsigned char)(N>>8); 146 154 t->i2c_set_freq[2] = (unsigned char) N; 147 155 t->i2c_set_freq[3] = 0x40; 148 156 t->i2c_set_freq[4] = 0x52; 149 - t->i2c_set_freq[5] = get_freq_entry(band_table, t->freq); 150 - t->i2c_set_freq[6] = get_freq_entry(agc_table, t->freq); 157 + t->i2c_set_freq[5] = get_freq_entry(band_table, freq); 158 + t->i2c_set_freq[6] = get_freq_entry(agc_table, freq); 151 159 t->i2c_set_freq[7] = 0x8f; 152 160 } 153 161
+3 -4
drivers/media/video/tda9887.c
··· 368 368 if (t->radio_mode == V4L2_TUNER_MODE_MONO) 369 369 norm = &radio_mono; 370 370 else 371 - norm = &radio_stereo; 371 + norm = &radio_stereo; 372 372 } else { 373 373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { 374 374 if (tvnorms[i].std & t->std) { ··· 566 566 if (UNSET != t->pinnacle_id) { 567 567 tda9887_set_pinnacle(t,buf); 568 568 } 569 - 570 569 tda9887_set_config(t,buf); 571 570 tda9887_set_insmod(t,buf); 572 571 ··· 614 615 t->pinnacle_id = UNSET; 615 616 t->radio_mode = V4L2_TUNER_MODE_STEREO; 616 617 617 - i2c_set_clientdata(&t->client, t); 618 - i2c_attach_client(&t->client); 618 + i2c_set_clientdata(&t->client, t); 619 + i2c_attach_client(&t->client); 619 620 620 621 return 0; 621 622 }
+334
drivers/media/video/tea5767.c
··· 1 + /* 2 + * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview 3 + * I2C address is allways 0xC0. 4 + * 5 + * $Id: tea5767.c,v 1.11 2005/06/21 15:40:33 mchehab Exp $ 6 + * 7 + * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) 8 + * This code is placed under the terms of the GNU General Public License 9 + * 10 + * tea5767 autodetection thanks to Torsten Seeboth and Atsushi Nakagawa 11 + * from their contributions on DScaler. 12 + */ 13 + 14 + #include <linux/module.h> 15 + #include <linux/init.h> 16 + #include <linux/kernel.h> 17 + #include <linux/sched.h> 18 + #include <linux/string.h> 19 + #include <linux/timer.h> 20 + #include <linux/delay.h> 21 + #include <linux/errno.h> 22 + #include <linux/slab.h> 23 + #include <linux/videodev.h> 24 + #include <linux/i2c.h> 25 + #include <linux/i2c-algo-bit.h> 26 + 27 + #include <media/tuner.h> 28 + 29 + /* Declared at tuner-core.c */ 30 + extern unsigned int tuner_debug; 31 + 32 + #define PREFIX "TEA5767 " 33 + 34 + /*****************************************************************************/ 35 + 36 + /****************************** 37 + * Write mode register values * 38 + ******************************/ 39 + 40 + /* First register */ 41 + #define TEA5767_MUTE 0x80 /* Mutes output */ 42 + #define TEA5767_SEARCH 0x40 /* Activates station search */ 43 + /* Bits 0-5 for divider MSB */ 44 + 45 + /* Second register */ 46 + /* Bits 0-7 for divider LSB */ 47 + 48 + /* Third register */ 49 + 50 + /* Station search from botton to up */ 51 + #define TEA5767_SEARCH_UP 0x80 52 + 53 + /* Searches with ADC output = 10 */ 54 + #define TEA5767_SRCH_HIGH_LVL 0x60 55 + 56 + /* Searches with ADC output = 10 */ 57 + #define TEA5767_SRCH_MID_LVL 0x40 58 + 59 + /* Searches with ADC output = 5 */ 60 + #define TEA5767_SRCH_LOW_LVL 0x20 61 + 62 + /* if on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq) */ 63 + #define TEA5767_HIGH_LO_INJECT 0x10 64 + 65 + /* Disable stereo */ 66 + #define TEA5767_MONO 0x08 67 + 68 + /* Disable right channel and turns to mono */ 69 + #define TEA5767_MUTE_RIGHT 0x04 70 + 71 + /* Disable left channel and turns to mono */ 72 + #define TEA5767_MUTE_LEFT 0x02 73 + 74 + #define TEA5767_PORT1_HIGH 0x01 75 + 76 + /* Forth register */ 77 + #define TEA5767_PORT2_HIGH 0x80 78 + /* Chips stops working. Only I2C bus remains on */ 79 + #define TEA5767_STDBY 0x40 80 + 81 + /* Japan freq (76-108 MHz. If disabled, 87.5-108 MHz */ 82 + #define TEA5767_JAPAN_BAND 0x20 83 + 84 + /* Unselected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz */ 85 + #define TEA5767_XTAL_32768 0x10 86 + 87 + /* Cuts weak signals */ 88 + #define TEA5767_SOFT_MUTE 0x08 89 + 90 + /* Activates high cut control */ 91 + #define TEA5767_HIGH_CUT_CTRL 0x04 92 + 93 + /* Activates stereo noise control */ 94 + #define TEA5767_ST_NOISE_CTL 0x02 95 + 96 + /* If activate PORT 1 indicates SEARCH or else it is used as PORT1 */ 97 + #define TEA5767_SRCH_IND 0x01 98 + 99 + /* Fiveth register */ 100 + 101 + /* By activating, it will use Xtal at 13 MHz as reference for divider */ 102 + #define TEA5767_PLLREF_ENABLE 0x80 103 + 104 + /* By activating, deemphasis=50, or else, deemphasis of 50us */ 105 + #define TEA5767_DEEMPH_75 0X40 106 + 107 + /***************************** 108 + * Read mode register values * 109 + *****************************/ 110 + 111 + /* First register */ 112 + #define TEA5767_READY_FLAG_MASK 0x80 113 + #define TEA5767_BAND_LIMIT_MASK 0X40 114 + /* Bits 0-5 for divider MSB after search or preset */ 115 + 116 + /* Second register */ 117 + /* Bits 0-7 for divider LSB after search or preset */ 118 + 119 + /* Third register */ 120 + #define TEA5767_STEREO_MASK 0x80 121 + #define TEA5767_IF_CNTR_MASK 0x7f 122 + 123 + /* Four register */ 124 + #define TEA5767_ADC_LEVEL_MASK 0xf0 125 + 126 + /* should be 0 */ 127 + #define TEA5767_CHIP_ID_MASK 0x0f 128 + 129 + /* Fiveth register */ 130 + /* Reserved for future extensions */ 131 + #define TEA5767_RESERVED_MASK 0xff 132 + 133 + /*****************************************************************************/ 134 + 135 + static void set_tv_freq(struct i2c_client *c, unsigned int freq) 136 + { 137 + struct tuner *t = i2c_get_clientdata(c); 138 + 139 + tuner_warn("This tuner doesn't support TV freq.\n"); 140 + } 141 + 142 + static void tea5767_status_dump(unsigned char *buffer) 143 + { 144 + unsigned int div, frq; 145 + 146 + if (TEA5767_READY_FLAG_MASK & buffer[0]) 147 + printk(PREFIX "Ready Flag ON\n"); 148 + else 149 + printk(PREFIX "Ready Flag OFF\n"); 150 + 151 + if (TEA5767_BAND_LIMIT_MASK & buffer[0]) 152 + printk(PREFIX "Tuner at band limit\n"); 153 + else 154 + printk(PREFIX "Tuner not at band limit\n"); 155 + 156 + div=((buffer[0]&0x3f)<<8) | buffer[1]; 157 + 158 + switch (TEA5767_HIGH_LO_32768) { 159 + case TEA5767_HIGH_LO_13MHz: 160 + frq = 1000*(div*50-700-225)/4; /* Freq in KHz */ 161 + break; 162 + case TEA5767_LOW_LO_13MHz: 163 + frq = 1000*(div*50+700+225)/4; /* Freq in KHz */ 164 + break; 165 + case TEA5767_LOW_LO_32768: 166 + frq = 1000*(div*32768/1000+700+225)/4; /* Freq in KHz */ 167 + break; 168 + case TEA5767_HIGH_LO_32768: 169 + default: 170 + frq = 1000*(div*32768/1000-700-225)/4; /* Freq in KHz */ 171 + break; 172 + } 173 + buffer[0] = (div>>8) & 0x3f; 174 + buffer[1] = div & 0xff; 175 + 176 + printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n", 177 + frq/1000,frq%1000,div); 178 + 179 + if (TEA5767_STEREO_MASK & buffer[2]) 180 + printk(PREFIX "Stereo\n"); 181 + else 182 + printk(PREFIX "Mono\n"); 183 + 184 + printk(PREFIX "IF Counter = %d\n",buffer[2] & TEA5767_IF_CNTR_MASK); 185 + 186 + printk(PREFIX "ADC Level = %d\n",(buffer[3] & TEA5767_ADC_LEVEL_MASK)>>4); 187 + 188 + printk(PREFIX "Chip ID = %d\n",(buffer[3] & TEA5767_CHIP_ID_MASK)); 189 + 190 + printk(PREFIX "Reserved = 0x%02x\n",(buffer[4] & TEA5767_RESERVED_MASK)); 191 + } 192 + 193 + /* Freq should be specifyed at 62.5 Hz */ 194 + static void set_radio_freq(struct i2c_client *c, unsigned int frq) 195 + { 196 + struct tuner *t = i2c_get_clientdata(c); 197 + unsigned char buffer[5]; 198 + unsigned div; 199 + int rc; 200 + 201 + if ( tuner_debug ) 202 + printk(PREFIX "radio freq counter %d\n",frq); 203 + 204 + /* Rounds freq to next decimal value - for 62.5 KHz step */ 205 + /* frq = 20*(frq/16)+radio_frq[frq%16]; */ 206 + 207 + buffer[2] = TEA5767_PORT1_HIGH; 208 + buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; 209 + buffer[4]=0; 210 + 211 + if (t->audmode == V4L2_TUNER_MODE_MONO) { 212 + tuner_dbg("TEA5767 set to mono\n"); 213 + buffer[2] |= TEA5767_MONO; 214 + } else 215 + tuner_dbg("TEA5767 set to stereo\n"); 216 + 217 + switch (t->type) { 218 + case TEA5767_HIGH_LO_13MHz: 219 + tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n"); 220 + buffer[2] |= TEA5767_HIGH_LO_INJECT; 221 + buffer[4] |= TEA5767_PLLREF_ENABLE; 222 + div = (frq*4/16+700+225+25)/50; 223 + break; 224 + case TEA5767_LOW_LO_13MHz: 225 + tuner_dbg("TEA5767 radio LOW LO inject xtal @ 13 MHz\n"); 226 + 227 + buffer[4] |= TEA5767_PLLREF_ENABLE; 228 + div = (frq*4/16-700-225+25)/50; 229 + break; 230 + case TEA5767_LOW_LO_32768: 231 + tuner_dbg("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n"); 232 + buffer[3] |= TEA5767_XTAL_32768; 233 + /* const 700=4000*175 Khz - to adjust freq to right value */ 234 + div = (1000*(frq*4/16-700-225)+16384)>>15; 235 + break; 236 + case TEA5767_HIGH_LO_32768: 237 + default: 238 + tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n"); 239 + 240 + buffer[2] |= TEA5767_HIGH_LO_INJECT; 241 + buffer[3] |= TEA5767_XTAL_32768; 242 + div = (1000*(frq*4/16+700+225)+16384)>>15; 243 + break; 244 + } 245 + buffer[0] = (div>>8) & 0x3f; 246 + buffer[1] = div & 0xff; 247 + 248 + if ( tuner_debug ) 249 + tea5767_status_dump(buffer); 250 + 251 + if (5 != (rc = i2c_master_send(c,buffer,5))) 252 + tuner_warn("i2c i/o error: rc == %d (should be 5)\n",rc); 253 + } 254 + 255 + static int tea5767_signal(struct i2c_client *c) 256 + { 257 + unsigned char buffer[5]; 258 + int rc; 259 + struct tuner *t = i2c_get_clientdata(c); 260 + 261 + memset(buffer,0,sizeof(buffer)); 262 + if (5 != (rc = i2c_master_recv(c,buffer,5))) 263 + tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc); 264 + 265 + return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) <<(13-4)); 266 + } 267 + 268 + static int tea5767_stereo(struct i2c_client *c) 269 + { 270 + unsigned char buffer[5]; 271 + int rc; 272 + struct tuner *t = i2c_get_clientdata(c); 273 + 274 + memset(buffer,0,sizeof(buffer)); 275 + if (5 != (rc = i2c_master_recv(c,buffer,5))) 276 + tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc); 277 + 278 + rc = buffer[2] & TEA5767_STEREO_MASK; 279 + 280 + if ( tuner_debug ) 281 + tuner_dbg("TEA5767 radio ST GET = %02x\n", rc); 282 + 283 + return ( (buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO: 0); 284 + } 285 + 286 + int tea_detection(struct i2c_client *c) 287 + { 288 + unsigned char buffer[5]= { 0xff, 0xff, 0xff, 0xff, 0xff }; 289 + int rc; 290 + struct tuner *t = i2c_get_clientdata(c); 291 + 292 + if (5 != (rc = i2c_master_recv(c,buffer,5))) { 293 + tuner_warn ( "it is not a TEA5767. Received %i chars.\n",rc ); 294 + return EINVAL; 295 + } 296 + 297 + /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */ 298 + if (buffer[0] == buffer[1] && buffer[0] == buffer[2] && 299 + buffer[0] == buffer[3] && buffer[0] == buffer[4]) { 300 + tuner_warn ( "All bytes are equal. It is not a TEA5767\n" ); 301 + return EINVAL; 302 + } 303 + 304 + /* Status bytes: 305 + * Byte 4: bit 3:1 : CI (Chip Identification) == 0 306 + * bit 0 : internally set to 0 307 + * Byte 5: bit 7:0 : == 0 308 + */ 309 + 310 + if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) { 311 + tuner_warn ( "Chip ID is not zero. It is not a TEA5767\n" ); 312 + return EINVAL; 313 + } 314 + tuner_warn ( "TEA5767 detected.\n" ); 315 + return 0; 316 + } 317 + 318 + int tea5767_tuner_init(struct i2c_client *c) 319 + { 320 + struct tuner *t = i2c_get_clientdata(c); 321 + 322 + if (tea_detection(c)==EINVAL) return EINVAL; 323 + 324 + tuner_info("type set to %d (%s)\n", 325 + t->type, TEA5767_TUNER_NAME); 326 + strlcpy(c->name, TEA5767_TUNER_NAME, sizeof(c->name)); 327 + 328 + t->tv_freq = set_tv_freq; 329 + t->radio_freq = set_radio_freq; 330 + t->has_signal = tea5767_signal; 331 + t->is_stereo = tea5767_stereo; 332 + 333 + return (0); 334 + }
+85 -78
drivers/media/video/tuner-core.c
··· 1 1 /* 2 - * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $ 2 + * $Id: tuner-core.c,v 1.29 2005/06/21 15:40:33 mchehab Exp $ 3 3 * 4 4 * i2c tv tuner chip device driver 5 5 * core core, i.e. kernel interfaces, registering and so on ··· 26 26 /* 27 27 * comment line bellow to return to old behavor, where only one I2C device is supported 28 28 */ 29 - #define CONFIG_TUNER_MULTI_I2C /**/ 30 29 31 30 #define UNSET (-1U) 32 31 ··· 57 58 MODULE_LICENSE("GPL"); 58 59 59 60 static int this_adap; 60 - #ifdef CONFIG_TUNER_MULTI_I2C 61 61 static unsigned short first_tuner, tv_tuner, radio_tuner; 62 - #endif 63 62 64 63 static struct i2c_driver driver; 65 64 static struct i2c_client client_template; ··· 78 81 return; 79 82 } 80 83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 81 - 82 - if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) { 83 - /* V4L2_TUNER_CAP_LOW frequency */ 84 - 85 - tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n"); 86 - 87 - t->tv_freq(c,freq>>10); 88 - 89 - return; 90 - } else { 91 - /* FIXME: better do that chip-specific, but 92 - right now we don't have that in the config 93 - struct and this way is still better than no 94 - check at all */ 95 84 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n", 96 85 freq/16,freq%16*100/16,tv_range[0],tv_range[1]); 97 - return; 98 - } 99 86 } 100 - tuner_dbg("62.5 Khz freq step selected for TV.\n"); 101 87 t->tv_freq(c,freq); 102 88 } 103 89 ··· 96 116 tuner_info("no radio tuning for this one, sorry.\n"); 97 117 return; 98 118 } 99 - if (freq < radio_range[0]*16 || freq > radio_range[1]*16) { 100 - if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) { 101 - /* V4L2_TUNER_CAP_LOW frequency */ 102 - if (t->type == TUNER_TEA5767) { 103 - tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000); 104 - t->radio_freq(c,freq>>10); 105 - return; 106 - } 107 - 108 - tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n"); 109 - 110 - tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000); 111 - 112 - t->radio_freq(c,freq>>10); 113 - return; 114 - 115 - } else { 116 - tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n", 117 - freq/16,freq%16*100/16, 118 - radio_range[0],radio_range[1]); 119 - return; 120 - } 119 + if (freq >= radio_range[0]*16000 && freq <= radio_range[1]*16000) { 120 + if (tuner_debug) 121 + tuner_info("radio freq step 62.5Hz (%d.%06d)\n", 122 + freq/16000,freq%16000*1000/16); 123 + t->radio_freq(c,freq); 124 + } else { 125 + tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n", 126 + freq/16,freq%16*100/16, 127 + radio_range[0],radio_range[1]); 121 128 } 122 - tuner_dbg("62.5 Khz freq step selected for Radio.\n"); 123 - t->radio_freq(c,freq); 129 + 130 + return; 124 131 } 125 132 126 133 static void set_freq(struct i2c_client *c, unsigned long freq) ··· 133 166 static void set_type(struct i2c_client *c, unsigned int type) 134 167 { 135 168 struct tuner *t = i2c_get_clientdata(c); 169 + unsigned char buffer[4]; 136 170 137 - tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type); 138 171 /* sanity check */ 139 172 if (type == UNSET || type == TUNER_ABSENT) 140 173 return; ··· 146 179 t->type = type; 147 180 return; 148 181 } 149 - if (t->initialized) 150 - /* run only once */ 182 + if ((t->initialized) && (t->type == type)) 183 + /* run only once except type change Hac 04/05*/ 151 184 return; 152 185 153 186 t->initialized = 1; ··· 160 193 case TUNER_PHILIPS_TDA8290: 161 194 tda8290_init(c); 162 195 break; 196 + case TUNER_TEA5767: 197 + if (tea5767_tuner_init(c)==EINVAL) t->type=TUNER_ABSENT; 198 + break; 199 + case TUNER_PHILIPS_FMD1216ME_MK3: 200 + buffer[0] = 0x0b; 201 + buffer[1] = 0xdc; 202 + buffer[2] = 0x9c; 203 + buffer[3] = 0x60; 204 + i2c_master_send(c,buffer,4); 205 + mdelay(1); 206 + buffer[2] = 0x86; 207 + buffer[3] = 0x54; 208 + i2c_master_send(c,buffer,4); 209 + default_tuner_init(c); 210 + break; 163 211 default: 212 + /* TEA5767 autodetection code */ 213 + if (tea5767_tuner_init(c)!=EINVAL) { 214 + t->type = TUNER_TEA5767; 215 + if (first_tuner == 0x60) 216 + first_tuner++; 217 + break; 218 + } 219 + 164 220 default_tuner_init(c); 165 221 break; 166 222 } 223 + tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type); 167 224 } 168 225 169 - #ifdef CONFIG_TUNER_MULTI_I2C 170 226 #define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \ 171 - return 0; } else \ 227 + return 0; } else if (tuner_debug) \ 172 228 tuner_info ("Cmd %s accepted to "tun"\n",cmd); 173 229 #define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \ 174 230 CHECK_ADDR(radio_tuner,cmd,"radio") } else \ 175 231 { CHECK_ADDR(tv_tuner,cmd,"TV"); } 176 - #else 177 - #define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd); 178 - #define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd); 179 - #endif 180 - 181 - #ifdef CONFIG_TUNER_MULTI_I2C 182 232 183 233 static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr) 184 234 { ··· 226 242 } 227 243 set_type(c,tun_addr->type); 228 244 } 229 - #else 230 - #define set_addr(c,tun_addr) set_type(c,(tun_addr)->type) 231 - #endif 232 245 233 246 static char pal[] = "-"; 234 247 module_param_string(pal, pal, sizeof(pal), 0644); ··· 265 284 { 266 285 struct tuner *t; 267 286 268 - #ifndef CONFIG_TUNER_MULTI_I2C 269 - if (this_adap > 0) 270 - return -1; 271 - #else 272 287 /* by default, first I2C card is both tv and radio tuner */ 273 288 if (this_adap == 0) { 274 289 first_tuner = addr; 275 290 tv_tuner = addr; 276 291 radio_tuner = addr; 277 292 } 278 - #endif 279 293 this_adap++; 280 294 281 295 client_template.adapter = adap; ··· 284 308 i2c_set_clientdata(&t->i2c, t); 285 309 t->type = UNSET; 286 310 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */ 311 + t->audmode = V4L2_TUNER_MODE_STEREO; 287 312 288 313 i2c_attach_client(&t->i2c); 289 314 tuner_info("chip found @ 0x%x (%s)\n", ··· 302 325 } 303 326 this_adap = 0; 304 327 305 - #ifdef CONFIG_TUNER_MULTI_I2C 306 328 first_tuner = 0; 307 329 tv_tuner = 0; 308 330 radio_tuner = 0; 309 - #endif 310 331 311 332 if (adap->class & I2C_CLASS_TV_ANALOG) 312 333 return i2c_probe(adap, &addr_data, tuner_attach); ··· 367 392 t->radio_if2 = 41300 * 1000; 368 393 break; 369 394 } 370 - break; 371 - 395 + break; 372 396 /* --- v4l ioctls --- */ 373 397 /* take care: bttv does userspace copying, we'll get a 374 398 kernel pointer here... */ ··· 414 440 vt->signal = t->has_signal(client); 415 441 if (t->is_stereo) { 416 442 if (t->is_stereo(client)) 417 - vt-> flags |= VIDEO_TUNER_STEREO_ON; 443 + vt->flags |= VIDEO_TUNER_STEREO_ON; 418 444 else 419 - vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON; 445 + vt->flags &= ~VIDEO_TUNER_STEREO_ON; 420 446 } 421 447 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */ 448 + 449 + vt->rangelow = radio_range[0] * 16000; 450 + vt->rangehigh = radio_range[1] * 16000; 451 + 452 + } else { 453 + vt->rangelow = tv_range[0] * 16; 454 + vt->rangehigh = tv_range[1] * 16; 422 455 } 423 456 424 457 return 0; ··· 491 510 tuner -> signal = t->has_signal(client); 492 511 if (t->is_stereo) { 493 512 if (t->is_stereo(client)) { 494 - tuner -> capability |= V4L2_TUNER_CAP_STEREO; 495 - tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO; 513 + tuner -> rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO; 496 514 } else { 497 - tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO; 515 + tuner -> rxsubchans = V4L2_TUNER_SUB_MONO; 498 516 } 499 517 } 518 + tuner->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; 519 + tuner->audmode = t->audmode; 520 + 521 + tuner->rangelow = radio_range[0] * 16000; 522 + tuner->rangehigh = radio_range[1] * 16000; 523 + } else { 524 + tuner->rangelow = tv_range[0] * 16; 525 + tuner->rangehigh = tv_range[1] * 16; 500 526 } 501 - /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */ 502 - tuner->rangelow = tv_range[0] * 16; 503 - // tuner->rangehigh = tv_range[1] * 16; 504 - // tuner->rangelow = tv_range[0] * 16384; 505 - tuner->rangehigh = tv_range[1] * 16384; 506 527 break; 507 528 } 529 + case VIDIOC_S_TUNER: /* Allow changing radio range and audio mode */ 530 + { 531 + struct v4l2_tuner *tuner = arg; 532 + 533 + CHECK_ADDR(radio_tuner,"VIDIOC_S_TUNER","radio"); 534 + SWITCH_V4L2; 535 + 536 + /* To switch the audio mode, applications initialize the 537 + index and audmode fields and the reserved array and 538 + call the VIDIOC_S_TUNER ioctl. */ 539 + /* rxsubchannels: V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO, 540 + V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2, 541 + V4L2_TUNER_MODE_SAP */ 542 + 543 + if (tuner->audmode == V4L2_TUNER_MODE_MONO) 544 + t->audmode = V4L2_TUNER_MODE_MONO; 545 + else 546 + t->audmode = V4L2_TUNER_MODE_STEREO; 547 + 548 + set_radio_freq(client, t->freq); 549 + break; 550 + } 551 + case TDA9887_SET_CONFIG: /* Nothing to do on tuner-core */ 552 + break; 508 553 default: 509 554 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd); 510 555 /* nothing */
+17 -17
drivers/media/video/tuner-simple.c
··· 1 1 /* 2 - * $Id: tuner-simple.c,v 1.21 2005/06/10 19:53:26 nsh Exp $ 2 + * $Id: tuner-simple.c,v 1.31 2005/06/21 16:02:25 mkrufky Exp $ 3 3 * 4 4 * i2c tv tuner chip device driver 5 5 * controls all those simple 4-control-bytes style tuners. ··· 207 207 { "LG PAL (TAPE series)", LGINNOTEK, PAL, 208 208 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623}, 209 209 210 - { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL, 211 - 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 212 - { "Philips FQ1236A MK4", Philips, NTSC, 213 - 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 210 + { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL, 211 + 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 212 + { "Philips FQ1236A MK4", Philips, NTSC, 213 + 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 214 214 215 215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */ 216 216 { "Ymec TVision TVF-8531MF", Philips, NTSC, 217 217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732}, 218 218 { "Ymec TVision TVF-5533MF", Philips, NTSC, 219 219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732}, 220 - 221 220 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC, 222 221 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 223 - { "Tena TNF9533-D/IF", LGINNOTEK, PAL, 224 - 16*160.25, 16*464.25, 0x01,0x02,0x08,0x8e,623}, 222 + /* Should work for TNF9533-D/IF, TNF9533-B/DF */ 223 + { "Tena TNF9533-D/IF", Philips, PAL, 224 + 16*160.25,16*464.25,0x01,0x02,0x04,0x8e,623}, 225 225 226 - /* 227 - * This entry is for TEA5767 FM radio only chip used on several boards 228 - * w/TV tuner 229 - */ 226 + /* This entry is for TEA5767 FM radio only chip used on several boards w/TV tuner */ 230 227 { TEA5767_TUNER_NAME, Philips, RADIO, 231 - -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0}, 228 + -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0}, 229 + { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL, 230 + 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 }, 232 231 }; 233 232 234 233 unsigned const int tuner_count = ARRAY_SIZE(tuners); ··· 454 455 int rc; 455 456 456 457 tun=&tuners[t->type]; 457 - div = freq + (int)(16*10.7); 458 + div = (freq / 1000) + (int)(16*10.7); 458 459 buffer[2] = tun->config; 459 460 460 461 switch (t->type) { 461 462 case TUNER_TENA_9533_DI: 462 463 case TUNER_YMEC_TVF_5533MF: 463 - 464 464 /*These values are empirically determinated */ 465 - div = (freq*122)/16 - 20; 465 + div = (freq * 122) / 16000 - 20; 466 466 buffer[2] = 0x88; /* could be also 0x80 */ 467 467 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */ 468 468 break; 469 469 case TUNER_PHILIPS_FM1216ME_MK3: 470 470 case TUNER_PHILIPS_FM1236_MK3: 471 + case TUNER_PHILIPS_FMD1216ME_MK3: 471 472 buffer[3] = 0x19; 472 473 break; 473 474 case TUNER_PHILIPS_FM1256_IH3: 474 - div = (20 * freq)/16 + 333 * 2; 475 + div = (20 * freq) / 16000 + 333 * 2; 475 476 buffer[2] = 0x80; 476 477 buffer[3] = 0x19; 477 478 break; ··· 504 505 t->radio_freq = default_set_radio_freq; 505 506 t->has_signal = tuner_signal; 506 507 t->is_stereo = tuner_stereo; 508 + 507 509 return 0; 508 510 } 509 511
+14 -6
include/media/tuner.h
··· 1 1 2 - /* 2 + /* $Id: tuner.h,v 1.33 2005/06/21 14:58:08 mkrufky Exp $ 3 + * 3 4 tuner.h - definition for different tuners 4 5 5 6 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de) ··· 23 22 24 23 #ifndef _TUNER_H 25 24 #define _TUNER_H 25 + 26 + #include <linux/videodev2.h> 26 27 27 28 #include "id.h" 28 29 ··· 91 88 #define TUNER_LG_NTSC_TAPE 47 92 89 93 90 #define TUNER_TNF_8831BGFF 48 94 - #define TUNER_MICROTUNE_4042FI5 49 /* FusionHDTV 3 Gold - 4042 FI5 (3X 8147) */ 91 + #define TUNER_MICROTUNE_4042FI5 49 /* DViCO FusionHDTV 3 Gold-Q - 4042 FI5 (3X 8147) */ 95 92 #define TUNER_TCL_2002N 50 96 93 #define TUNER_PHILIPS_FM1256_IH3 51 97 94 ··· 101 98 #define TUNER_LG_PAL_TAPE 55 /* Hauppauge PVR-150 PAL */ 102 99 103 100 #define TUNER_PHILIPS_FQ1216AME_MK4 56 /* Hauppauge PVR-150 PAL */ 104 - #define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */ 101 + #define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */ 105 102 106 103 #define TUNER_YMEC_TVF_8531MF 58 107 104 #define TUNER_YMEC_TVF_5533MF 59 /* Pixelview Pro Ultra NTSC */ 108 - #define TUNER_THOMSON_DTT7611 60 105 + #define TUNER_THOMSON_DTT7611 60 /* DViCO FusionHDTV 3 Gold-T */ 109 106 #define TUNER_TENA_9533_DI 61 107 + 110 108 #define TUNER_TEA5767 62 /* Only FM Radio Tuner */ 109 + #define TUNER_PHILIPS_FMD1216ME_MK3 63 111 110 112 111 #define TEA5767_TUNER_NAME "Philips TEA5767HN FM Radio" 113 - 114 - #define TUNER_THOMSON_DTT7611 60 115 112 116 113 #define NOTUNER 0 117 114 #define PAL 1 /* PAL_BG */ ··· 197 194 unsigned char i2c_easy_mode[2]; 198 195 unsigned char i2c_set_freq[8]; 199 196 197 + /* used to keep track of audmode */ 198 + unsigned int audmode; 199 + 200 200 /* function ptrs */ 201 201 void (*tv_freq)(struct i2c_client *c, unsigned int freq); 202 202 void (*radio_freq)(struct i2c_client *c, unsigned int freq); 203 203 int (*has_signal)(struct i2c_client *c); 204 204 int (*is_stereo)(struct i2c_client *c); 205 + int (*set_tuner)(struct i2c_client *c, struct v4l2_tuner *v); 205 206 }; 206 207 207 208 extern unsigned int tuner_debug; ··· 213 206 214 207 extern int microtune_init(struct i2c_client *c); 215 208 extern int tda8290_init(struct i2c_client *c); 209 + extern int tea5767_tuner_init(struct i2c_client *c); 216 210 extern int default_tuner_init(struct i2c_client *c); 217 211 218 212 #define tuner_warn(fmt, arg...) \