Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/moduleparam.h> |
| 3 | #include <linux/kernel.h> |
| 4 | #include <linux/i2c.h> |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/videodev.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/errno.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/delay.h> |
| 11 | |
| 12 | #include <media/audiochip.h> |
| 13 | #include <media/tuner.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame^] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | /* Chips: |
| 17 | TDA9885 (PAL, NTSC) |
| 18 | TDA9886 (PAL, SECAM, NTSC) |
| 19 | TDA9887 (PAL, SECAM, NTSC, FM Radio) |
| 20 | |
| 21 | found on: |
| 22 | - Pinnacle PCTV (Jul.2002 Version with MT2032, bttv) |
| 23 | TDA9887 (world), TDA9885 (USA) |
| 24 | Note: OP2 of tda988x must be set to 1, else MT2032 is disabled! |
| 25 | - KNC One TV-Station RDS (saa7134) |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 26 | - Hauppauge PVR-150/500 (possibly more) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | |
| 30 | /* Addresses to scan */ |
| 31 | static unsigned short normal_i2c[] = { |
| 32 | 0x84 >>1, |
| 33 | 0x86 >>1, |
| 34 | 0x96 >>1, |
| 35 | I2C_CLIENT_END, |
| 36 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | I2C_CLIENT_INSMOD; |
| 38 | |
| 39 | /* insmod options */ |
| 40 | static unsigned int debug = 0; |
| 41 | module_param(debug, int, 0644); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
| 44 | /* ---------------------------------------------------------------------- */ |
| 45 | |
| 46 | #define UNSET (-1U) |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 47 | #define tda9887_info(fmt, arg...) do {\ |
| 48 | printk(KERN_INFO "%s %d-%04x: " fmt, t->client.name, \ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 49 | i2c_adapter_id(t->client.adapter), t->client.addr , ##arg); } while (0) |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 50 | #define tda9887_dbg(fmt, arg...) do {\ |
| 51 | if (debug) \ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 52 | printk(KERN_INFO "%s %d-%04x: " fmt, t->client.name, \ |
| 53 | i2c_adapter_id(t->client.adapter), t->client.addr , ##arg); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | struct tda9887 { |
| 56 | struct i2c_client client; |
| 57 | v4l2_std_id std; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 58 | enum tuner_mode mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | unsigned int config; |
| 60 | unsigned int pinnacle_id; |
| 61 | unsigned int using_v4l2; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 62 | unsigned int radio_mode; |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 63 | unsigned char data[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct tvnorm { |
| 67 | v4l2_std_id std; |
| 68 | char *name; |
| 69 | unsigned char b; |
| 70 | unsigned char c; |
| 71 | unsigned char e; |
| 72 | }; |
| 73 | |
| 74 | static struct i2c_driver driver; |
| 75 | static struct i2c_client client_template; |
| 76 | |
| 77 | /* ---------------------------------------------------------------------- */ |
| 78 | |
| 79 | // |
| 80 | // TDA defines |
| 81 | // |
| 82 | |
| 83 | //// first reg (b) |
| 84 | #define cVideoTrapBypassOFF 0x00 // bit b0 |
| 85 | #define cVideoTrapBypassON 0x01 // bit b0 |
| 86 | |
| 87 | #define cAutoMuteFmInactive 0x00 // bit b1 |
| 88 | #define cAutoMuteFmActive 0x02 // bit b1 |
| 89 | |
| 90 | #define cIntercarrier 0x00 // bit b2 |
| 91 | #define cQSS 0x04 // bit b2 |
| 92 | |
| 93 | #define cPositiveAmTV 0x00 // bit b3:4 |
| 94 | #define cFmRadio 0x08 // bit b3:4 |
| 95 | #define cNegativeFmTV 0x10 // bit b3:4 |
| 96 | |
| 97 | |
| 98 | #define cForcedMuteAudioON 0x20 // bit b5 |
| 99 | #define cForcedMuteAudioOFF 0x00 // bit b5 |
| 100 | |
| 101 | #define cOutputPort1Active 0x00 // bit b6 |
| 102 | #define cOutputPort1Inactive 0x40 // bit b6 |
| 103 | |
| 104 | #define cOutputPort2Active 0x00 // bit b7 |
| 105 | #define cOutputPort2Inactive 0x80 // bit b7 |
| 106 | |
| 107 | |
| 108 | //// second reg (c) |
| 109 | #define cDeemphasisOFF 0x00 // bit c5 |
| 110 | #define cDeemphasisON 0x20 // bit c5 |
| 111 | |
| 112 | #define cDeemphasis75 0x00 // bit c6 |
| 113 | #define cDeemphasis50 0x40 // bit c6 |
| 114 | |
| 115 | #define cAudioGain0 0x00 // bit c7 |
| 116 | #define cAudioGain6 0x80 // bit c7 |
| 117 | |
| 118 | |
| 119 | //// third reg (e) |
| 120 | #define cAudioIF_4_5 0x00 // bit e0:1 |
| 121 | #define cAudioIF_5_5 0x01 // bit e0:1 |
| 122 | #define cAudioIF_6_0 0x02 // bit e0:1 |
| 123 | #define cAudioIF_6_5 0x03 // bit e0:1 |
| 124 | |
| 125 | |
| 126 | #define cVideoIF_58_75 0x00 // bit e2:4 |
| 127 | #define cVideoIF_45_75 0x04 // bit e2:4 |
| 128 | #define cVideoIF_38_90 0x08 // bit e2:4 |
| 129 | #define cVideoIF_38_00 0x0C // bit e2:4 |
| 130 | #define cVideoIF_33_90 0x10 // bit e2:4 |
| 131 | #define cVideoIF_33_40 0x14 // bit e2:4 |
| 132 | #define cRadioIF_45_75 0x18 // bit e2:4 |
| 133 | #define cRadioIF_38_90 0x1C // bit e2:4 |
| 134 | |
| 135 | |
| 136 | #define cTunerGainNormal 0x00 // bit e5 |
| 137 | #define cTunerGainLow 0x20 // bit e5 |
| 138 | |
| 139 | #define cGating_18 0x00 // bit e6 |
| 140 | #define cGating_36 0x40 // bit e6 |
| 141 | |
| 142 | #define cAgcOutON 0x80 // bit e7 |
| 143 | #define cAgcOutOFF 0x00 // bit e7 |
| 144 | |
| 145 | /* ---------------------------------------------------------------------- */ |
| 146 | |
| 147 | static struct tvnorm tvnorms[] = { |
| 148 | { |
| 149 | .std = V4L2_STD_PAL_BG, |
| 150 | .name = "PAL-BG", |
| 151 | .b = ( cNegativeFmTV | |
| 152 | cQSS ), |
| 153 | .c = ( cDeemphasisON | |
| 154 | cDeemphasis50 ), |
| 155 | .e = ( cAudioIF_5_5 | |
| 156 | cVideoIF_38_90 ), |
| 157 | },{ |
| 158 | .std = V4L2_STD_PAL_I, |
| 159 | .name = "PAL-I", |
| 160 | .b = ( cNegativeFmTV | |
| 161 | cQSS ), |
| 162 | .c = ( cDeemphasisON | |
| 163 | cDeemphasis50 ), |
| 164 | .e = ( cAudioIF_6_0 | |
| 165 | cVideoIF_38_90 ), |
| 166 | },{ |
| 167 | .std = V4L2_STD_PAL_DK, |
| 168 | .name = "PAL-DK", |
| 169 | .b = ( cNegativeFmTV | |
| 170 | cQSS ), |
| 171 | .c = ( cDeemphasisON | |
| 172 | cDeemphasis50 ), |
| 173 | .e = ( cAudioIF_6_5 | |
| 174 | cVideoIF_38_00 ), |
| 175 | },{ |
| 176 | .std = V4L2_STD_PAL_M | V4L2_STD_PAL_N, |
| 177 | .name = "PAL-M/N", |
| 178 | .b = ( cNegativeFmTV | |
| 179 | cQSS ), |
| 180 | .c = ( cDeemphasisON | |
| 181 | cDeemphasis75 ), |
| 182 | .e = ( cAudioIF_4_5 | |
| 183 | cVideoIF_45_75 ), |
| 184 | },{ |
| 185 | .std = V4L2_STD_SECAM_L, |
| 186 | .name = "SECAM-L", |
| 187 | .b = ( cPositiveAmTV | |
| 188 | cQSS ), |
Nickolay V. Shmyrev | 3375c39 | 2005-11-08 21:37:05 -0800 | [diff] [blame] | 189 | .e = ( cGating_36 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 190 | cAudioIF_6_5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | cVideoIF_38_90 ), |
| 192 | },{ |
| 193 | .std = V4L2_STD_SECAM_DK, |
| 194 | .name = "SECAM-DK", |
| 195 | .b = ( cNegativeFmTV | |
| 196 | cQSS ), |
| 197 | .c = ( cDeemphasisON | |
| 198 | cDeemphasis50 ), |
| 199 | .e = ( cAudioIF_6_5 | |
| 200 | cVideoIF_38_00 ), |
| 201 | },{ |
| 202 | .std = V4L2_STD_NTSC_M, |
| 203 | .name = "NTSC-M", |
| 204 | .b = ( cNegativeFmTV | |
| 205 | cQSS ), |
| 206 | .c = ( cDeemphasisON | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 207 | cDeemphasis75 ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | .e = ( cGating_36 | |
| 209 | cAudioIF_4_5 | |
| 210 | cVideoIF_45_75 ), |
| 211 | },{ |
| 212 | .std = V4L2_STD_NTSC_M_JP, |
| 213 | .name = "NTSC-JP", |
| 214 | .b = ( cNegativeFmTV | |
| 215 | cQSS ), |
| 216 | .c = ( cDeemphasisON | |
| 217 | cDeemphasis50 ), |
| 218 | .e = ( cGating_36 | |
| 219 | cAudioIF_4_5 | |
| 220 | cVideoIF_58_75 ), |
| 221 | } |
| 222 | }; |
| 223 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 224 | static struct tvnorm radio_stereo = { |
| 225 | .name = "Radio Stereo", |
| 226 | .b = ( cFmRadio | |
| 227 | cQSS ), |
| 228 | .c = ( cDeemphasisOFF | |
| 229 | cAudioGain6 ), |
| 230 | .e = ( cAudioIF_5_5 | |
| 231 | cRadioIF_38_90 ), |
| 232 | }; |
| 233 | |
| 234 | static struct tvnorm radio_mono = { |
| 235 | .name = "Radio Mono", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | .b = ( cFmRadio | |
| 237 | cQSS ), |
| 238 | .c = ( cDeemphasisON | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 239 | cDeemphasis50), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | .e = ( cAudioIF_5_5 | |
| 241 | cRadioIF_38_90 ), |
| 242 | }; |
| 243 | |
| 244 | /* ---------------------------------------------------------------------- */ |
| 245 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 246 | static void dump_read_message(struct tda9887 *t, unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | static char *afc[16] = { |
| 249 | "- 12.5 kHz", |
| 250 | "- 37.5 kHz", |
| 251 | "- 62.5 kHz", |
| 252 | "- 87.5 kHz", |
| 253 | "-112.5 kHz", |
| 254 | "-137.5 kHz", |
| 255 | "-162.5 kHz", |
| 256 | "-187.5 kHz [min]", |
| 257 | "+187.5 kHz [max]", |
| 258 | "+162.5 kHz", |
| 259 | "+137.5 kHz", |
| 260 | "+112.5 kHz", |
| 261 | "+ 87.5 kHz", |
| 262 | "+ 62.5 kHz", |
| 263 | "+ 37.5 kHz", |
| 264 | "+ 12.5 kHz", |
| 265 | }; |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 266 | tda9887_info("read: 0x%2x\n", buf[0]); |
| 267 | tda9887_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no"); |
| 268 | tda9887_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]); |
| 269 | tda9887_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low"); |
| 270 | tda9887_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out"); |
| 271 | tda9887_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 274 | static void dump_write_message(struct tda9887 *t, unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
| 276 | static char *sound[4] = { |
| 277 | "AM/TV", |
| 278 | "FM/radio", |
| 279 | "FM/TV", |
| 280 | "FM/radio" |
| 281 | }; |
| 282 | static char *adjust[32] = { |
| 283 | "-16", "-15", "-14", "-13", "-12", "-11", "-10", "-9", |
| 284 | "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", |
| 285 | "0", "+1", "+2", "+3", "+4", "+5", "+6", "+7", |
| 286 | "+8", "+9", "+10", "+11", "+12", "+13", "+14", "+15" |
| 287 | }; |
| 288 | static char *deemph[4] = { |
| 289 | "no", "no", "75", "50" |
| 290 | }; |
| 291 | static char *carrier[4] = { |
| 292 | "4.5 MHz", |
| 293 | "5.5 MHz", |
| 294 | "6.0 MHz", |
| 295 | "6.5 MHz / AM" |
| 296 | }; |
| 297 | static char *vif[8] = { |
| 298 | "58.75 MHz", |
| 299 | "45.75 MHz", |
| 300 | "38.9 MHz", |
| 301 | "38.0 MHz", |
| 302 | "33.9 MHz", |
| 303 | "33.4 MHz", |
| 304 | "45.75 MHz + pin13", |
| 305 | "38.9 MHz + pin13", |
| 306 | }; |
| 307 | static char *rif[4] = { |
| 308 | "44 MHz", |
| 309 | "52 MHz", |
| 310 | "52 MHz", |
| 311 | "44 MHz", |
| 312 | }; |
| 313 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 314 | tda9887_info("write: byte B 0x%02x\n",buf[1]); |
| 315 | tda9887_info(" B0 video mode : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | (buf[1] & 0x01) ? "video trap" : "sound trap"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 317 | tda9887_info(" B1 auto mute fm : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | (buf[1] & 0x02) ? "yes" : "no"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 319 | tda9887_info(" B2 carrier mode : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | (buf[1] & 0x04) ? "QSS" : "Intercarrier"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 321 | tda9887_info(" B3-4 tv sound/radio : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | sound[(buf[1] & 0x18) >> 3]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 323 | tda9887_info(" B5 force mute audio: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | (buf[1] & 0x20) ? "yes" : "no"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 325 | tda9887_info(" B6 output port 1 : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | (buf[1] & 0x40) ? "high (inactive)" : "low (active)"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 327 | tda9887_info(" B7 output port 2 : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | (buf[1] & 0x80) ? "high (inactive)" : "low (active)"); |
| 329 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 330 | tda9887_info("write: byte C 0x%02x\n",buf[2]); |
| 331 | tda9887_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]); |
| 332 | tda9887_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]); |
| 333 | tda9887_info(" C7 audio gain : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | (buf[2] & 0x80) ? "-6" : "0"); |
| 335 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 336 | tda9887_info("write: byte E 0x%02x\n",buf[3]); |
| 337 | tda9887_info(" E0-1 sound carrier : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | carrier[(buf[3] & 0x03)]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 339 | tda9887_info(" E6 l pll gating : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | (buf[3] & 0x40) ? "36" : "13"); |
| 341 | |
| 342 | if (buf[1] & 0x08) { |
| 343 | /* radio */ |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 344 | tda9887_info(" E2-4 video if : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | rif[(buf[3] & 0x0c) >> 2]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 346 | tda9887_info(" E7 vif agc output : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | (buf[3] & 0x80) |
| 348 | ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio") |
| 349 | : "fm radio carrier afc"); |
| 350 | } else { |
| 351 | /* video */ |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 352 | tda9887_info(" E2-4 video if : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | vif[(buf[3] & 0x1c) >> 2]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 354 | tda9887_info(" E5 tuner gain : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | (buf[3] & 0x80) |
| 356 | ? ((buf[3] & 0x20) ? "external" : "normal") |
| 357 | : ((buf[3] & 0x20) ? "minimum" : "normal")); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 358 | tda9887_info(" E7 vif agc output : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | (buf[3] & 0x80) |
| 360 | ? ((buf[3] & 0x20) |
| 361 | ? "pin3 port, pin22 vif agc out" |
| 362 | : "pin22 port, pin3 vif acg ext in") |
| 363 | : "pin3+pin22 port"); |
| 364 | } |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 365 | tda9887_info("--\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /* ---------------------------------------------------------------------- */ |
| 369 | |
| 370 | static int tda9887_set_tvnorm(struct tda9887 *t, char *buf) |
| 371 | { |
| 372 | struct tvnorm *norm = NULL; |
| 373 | int i; |
| 374 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 375 | if (t->mode == T_RADIO) { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 376 | if (t->radio_mode == V4L2_TUNER_MODE_MONO) |
| 377 | norm = &radio_mono; |
| 378 | else |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 379 | norm = &radio_stereo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } else { |
| 381 | for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { |
| 382 | if (tvnorms[i].std & t->std) { |
| 383 | norm = tvnorms+i; |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | if (NULL == norm) { |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 389 | tda9887_dbg("Unsupported tvnorm entry - audio muted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return -1; |
| 391 | } |
| 392 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 393 | tda9887_dbg("configure for: %s\n",norm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | buf[1] = norm->b; |
| 395 | buf[2] = norm->c; |
| 396 | buf[3] = norm->e; |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static unsigned int port1 = UNSET; |
| 401 | static unsigned int port2 = UNSET; |
| 402 | static unsigned int qss = UNSET; |
| 403 | static unsigned int adjust = 0x10; |
| 404 | module_param(port1, int, 0644); |
| 405 | module_param(port2, int, 0644); |
| 406 | module_param(qss, int, 0644); |
| 407 | module_param(adjust, int, 0644); |
| 408 | |
| 409 | static int tda9887_set_insmod(struct tda9887 *t, char *buf) |
| 410 | { |
| 411 | if (UNSET != port1) { |
| 412 | if (port1) |
| 413 | buf[1] |= cOutputPort1Inactive; |
| 414 | else |
| 415 | buf[1] &= ~cOutputPort1Inactive; |
| 416 | } |
| 417 | if (UNSET != port2) { |
| 418 | if (port2) |
| 419 | buf[1] |= cOutputPort2Inactive; |
| 420 | else |
| 421 | buf[1] &= ~cOutputPort2Inactive; |
| 422 | } |
| 423 | |
| 424 | if (UNSET != qss) { |
| 425 | if (qss) |
| 426 | buf[1] |= cQSS; |
| 427 | else |
| 428 | buf[1] &= ~cQSS; |
| 429 | } |
| 430 | |
| 431 | if (adjust >= 0x00 && adjust < 0x20) |
| 432 | buf[2] |= adjust; |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int tda9887_set_config(struct tda9887 *t, char *buf) |
| 437 | { |
| 438 | if (t->config & TDA9887_PORT1_ACTIVE) |
| 439 | buf[1] &= ~cOutputPort1Inactive; |
| 440 | if (t->config & TDA9887_PORT1_INACTIVE) |
| 441 | buf[1] |= cOutputPort1Inactive; |
| 442 | if (t->config & TDA9887_PORT2_ACTIVE) |
| 443 | buf[1] &= ~cOutputPort2Inactive; |
| 444 | if (t->config & TDA9887_PORT2_INACTIVE) |
| 445 | buf[1] |= cOutputPort2Inactive; |
| 446 | |
| 447 | if (t->config & TDA9887_QSS) |
| 448 | buf[1] |= cQSS; |
| 449 | if (t->config & TDA9887_INTERCARRIER) |
| 450 | buf[1] &= ~cQSS; |
| 451 | |
| 452 | if (t->config & TDA9887_AUTOMUTE) |
| 453 | buf[1] |= cAutoMuteFmActive; |
| 454 | if (t->config & TDA9887_DEEMPHASIS_MASK) { |
| 455 | buf[2] &= ~0x60; |
| 456 | switch (t->config & TDA9887_DEEMPHASIS_MASK) { |
| 457 | case TDA9887_DEEMPHASIS_NONE: |
| 458 | buf[2] |= cDeemphasisOFF; |
| 459 | break; |
| 460 | case TDA9887_DEEMPHASIS_50: |
| 461 | buf[2] |= cDeemphasisON | cDeemphasis50; |
| 462 | break; |
| 463 | case TDA9887_DEEMPHASIS_75: |
| 464 | buf[2] |= cDeemphasisON | cDeemphasis75; |
| 465 | break; |
| 466 | } |
| 467 | } |
Nickolay V. Shmyrev | 3ae1adc | 2005-11-08 21:37:39 -0800 | [diff] [blame] | 468 | if ((t->config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC)) |
| 469 | buf[1] &= ~cQSS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | /* ---------------------------------------------------------------------- */ |
| 474 | |
| 475 | static int tda9887_set_pinnacle(struct tda9887 *t, char *buf) |
| 476 | { |
| 477 | unsigned int bCarrierMode = UNSET; |
| 478 | |
| 479 | if (t->std & V4L2_STD_625_50) { |
| 480 | if ((1 == t->pinnacle_id) || (7 == t->pinnacle_id)) { |
| 481 | bCarrierMode = cIntercarrier; |
| 482 | } else { |
| 483 | bCarrierMode = cQSS; |
| 484 | } |
| 485 | } |
| 486 | if (t->std & V4L2_STD_525_60) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 487 | if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | bCarrierMode = cIntercarrier; |
| 489 | } else { |
| 490 | bCarrierMode = cQSS; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (bCarrierMode != UNSET) { |
| 495 | buf[1] &= ~0x04; |
| 496 | buf[1] |= bCarrierMode; |
| 497 | } |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /* ---------------------------------------------------------------------- */ |
| 502 | |
| 503 | static char pal[] = "-"; |
Bert Wesarg | 975e046 | 2005-04-16 15:25:43 -0700 | [diff] [blame] | 504 | module_param_string(pal, pal, sizeof(pal), 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | static char secam[] = "-"; |
Bert Wesarg | 975e046 | 2005-04-16 15:25:43 -0700 | [diff] [blame] | 506 | module_param_string(secam, secam, sizeof(secam), 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | static int tda9887_fixup_std(struct tda9887 *t) |
| 509 | { |
| 510 | /* get more precise norm info from insmod option */ |
| 511 | if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { |
| 512 | switch (pal[0]) { |
| 513 | case 'b': |
| 514 | case 'B': |
| 515 | case 'g': |
| 516 | case 'G': |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 517 | tda9887_dbg("insmod fixup: PAL => PAL-BG\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | t->std = V4L2_STD_PAL_BG; |
| 519 | break; |
| 520 | case 'i': |
| 521 | case 'I': |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 522 | tda9887_dbg("insmod fixup: PAL => PAL-I\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | t->std = V4L2_STD_PAL_I; |
| 524 | break; |
| 525 | case 'd': |
| 526 | case 'D': |
| 527 | case 'k': |
| 528 | case 'K': |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 529 | tda9887_dbg("insmod fixup: PAL => PAL-DK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | t->std = V4L2_STD_PAL_DK; |
| 531 | break; |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 532 | case '-': |
| 533 | /* default parameter, do nothing */ |
| 534 | break; |
| 535 | default: |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 536 | tda9887_info("pal= argument not recognised\n"); |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 537 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { |
| 541 | switch (secam[0]) { |
| 542 | case 'd': |
| 543 | case 'D': |
| 544 | case 'k': |
| 545 | case 'K': |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 546 | tda9887_dbg("insmod fixup: SECAM => SECAM-DK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | t->std = V4L2_STD_SECAM_DK; |
| 548 | break; |
| 549 | case 'l': |
| 550 | case 'L': |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 551 | tda9887_dbg("insmod fixup: SECAM => SECAM-L\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | t->std = V4L2_STD_SECAM_L; |
| 553 | break; |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 554 | case '-': |
| 555 | /* default parameter, do nothing */ |
| 556 | break; |
| 557 | default: |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 558 | tda9887_info("secam= argument not recognised\n"); |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 559 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static int tda9887_status(struct tda9887 *t) |
| 566 | { |
| 567 | unsigned char buf[1]; |
| 568 | int rc; |
| 569 | |
| 570 | memset(buf,0,sizeof(buf)); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 571 | if (1 != (rc = i2c_master_recv(&t->client,buf,1))) |
| 572 | tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 573 | dump_read_message(t, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int tda9887_configure(struct tda9887 *t) |
| 578 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | int rc; |
| 580 | |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 581 | memset(t->data,0,sizeof(t->data)); |
| 582 | tda9887_set_tvnorm(t,t->data); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 583 | |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 584 | t->data[1] |= cOutputPort1Inactive; |
| 585 | t->data[1] |= cOutputPort2Inactive; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | if (UNSET != t->pinnacle_id) { |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 588 | tda9887_set_pinnacle(t,t->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 590 | tda9887_set_config(t,t->data); |
| 591 | tda9887_set_insmod(t,t->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 593 | if (t->mode == T_STANDBY) { |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 594 | t->data[1] |= cForcedMuteAudioON; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 598 | tda9887_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n", |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 599 | t->data[1],t->data[2],t->data[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | if (debug > 1) |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 601 | dump_write_message(t, t->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 603 | if (4 != (rc = i2c_master_send(&t->client,t->data,4))) |
| 604 | tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | if (debug > 2) { |
| 607 | msleep_interruptible(1000); |
| 608 | tda9887_status(t); |
| 609 | } |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | /* ---------------------------------------------------------------------- */ |
| 614 | |
| 615 | static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind) |
| 616 | { |
| 617 | struct tda9887 *t; |
| 618 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 619 | client_template.adapter = adap; |
| 620 | client_template.addr = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 622 | if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL))) |
| 623 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | memset(t,0,sizeof(*t)); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | t->client = client_template; |
| 627 | t->std = 0; |
| 628 | t->pinnacle_id = UNSET; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 629 | t->radio_mode = V4L2_TUNER_MODE_STEREO; |
| 630 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 631 | tda9887_info("chip found @ 0x%x (%s)\n", addr<<1, adap->name); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 632 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 633 | i2c_set_clientdata(&t->client, t); |
| 634 | i2c_attach_client(&t->client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | static int tda9887_probe(struct i2c_adapter *adap) |
| 640 | { |
| 641 | #ifdef I2C_CLASS_TV_ANALOG |
| 642 | if (adap->class & I2C_CLASS_TV_ANALOG) |
| 643 | return i2c_probe(adap, &addr_data, tda9887_attach); |
| 644 | #else |
| 645 | switch (adap->id) { |
Jean Delvare | c7a4653 | 2005-08-11 23:41:56 +0200 | [diff] [blame] | 646 | case I2C_HW_B_BT848: |
| 647 | case I2C_HW_B_RIVA: |
Jean Delvare | 1684a984 | 2005-08-11 23:51:10 +0200 | [diff] [blame] | 648 | case I2C_HW_SAA7134: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return i2c_probe(adap, &addr_data, tda9887_attach); |
| 650 | break; |
| 651 | } |
| 652 | #endif |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static int tda9887_detach(struct i2c_client *client) |
| 657 | { |
| 658 | struct tda9887 *t = i2c_get_clientdata(client); |
| 659 | |
| 660 | i2c_detach_client(client); |
| 661 | kfree(t); |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | #define SWITCH_V4L2 if (!t->using_v4l2 && debug) \ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 666 | tda9887_info("switching to v4l2\n"); \ |
| 667 | t->using_v4l2 = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | #define CHECK_V4L2 if (t->using_v4l2) { if (debug) \ |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 669 | tda9887_info("ignore v4l1 call\n"); \ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 670 | return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | static int |
| 673 | tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) |
| 674 | { |
| 675 | struct tda9887 *t = i2c_get_clientdata(client); |
| 676 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 677 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
| 679 | /* --- configuration --- */ |
| 680 | case AUDC_SET_RADIO: |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 681 | { |
| 682 | t->mode = T_RADIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | tda9887_configure(t); |
| 684 | break; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 685 | } |
| 686 | case TUNER_SET_STANDBY: |
| 687 | { |
| 688 | t->mode = T_STANDBY; |
| 689 | tda9887_configure(t); |
| 690 | break; |
| 691 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | case AUDC_CONFIG_PINNACLE: |
| 693 | { |
| 694 | int *i = arg; |
| 695 | |
| 696 | t->pinnacle_id = *i; |
| 697 | tda9887_configure(t); |
| 698 | break; |
| 699 | } |
| 700 | case TDA9887_SET_CONFIG: |
| 701 | { |
| 702 | int *i = arg; |
| 703 | |
| 704 | t->config = *i; |
| 705 | tda9887_configure(t); |
| 706 | break; |
| 707 | } |
| 708 | /* --- v4l ioctls --- */ |
| 709 | /* take care: bttv does userspace copying, we'll get a |
| 710 | kernel pointer here... */ |
| 711 | case VIDIOCSCHAN: |
| 712 | { |
| 713 | static const v4l2_std_id map[] = { |
| 714 | [ VIDEO_MODE_PAL ] = V4L2_STD_PAL, |
| 715 | [ VIDEO_MODE_NTSC ] = V4L2_STD_NTSC_M, |
| 716 | [ VIDEO_MODE_SECAM ] = V4L2_STD_SECAM, |
| 717 | [ 4 /* bttv */ ] = V4L2_STD_PAL_M, |
| 718 | [ 5 /* bttv */ ] = V4L2_STD_PAL_N, |
| 719 | [ 6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, |
| 720 | }; |
| 721 | struct video_channel *vc = arg; |
| 722 | |
| 723 | CHECK_V4L2; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 724 | t->mode = T_ANALOG_TV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | if (vc->norm < ARRAY_SIZE(map)) |
| 726 | t->std = map[vc->norm]; |
| 727 | tda9887_fixup_std(t); |
| 728 | tda9887_configure(t); |
| 729 | break; |
| 730 | } |
| 731 | case VIDIOC_S_STD: |
| 732 | { |
| 733 | v4l2_std_id *id = arg; |
| 734 | |
| 735 | SWITCH_V4L2; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 736 | t->mode = T_ANALOG_TV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | t->std = *id; |
| 738 | tda9887_fixup_std(t); |
| 739 | tda9887_configure(t); |
| 740 | break; |
| 741 | } |
| 742 | case VIDIOC_S_FREQUENCY: |
| 743 | { |
| 744 | struct v4l2_frequency *f = arg; |
| 745 | |
| 746 | SWITCH_V4L2; |
| 747 | if (V4L2_TUNER_ANALOG_TV == f->type) { |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 748 | if (t->mode == T_ANALOG_TV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return 0; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 750 | t->mode = T_ANALOG_TV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | if (V4L2_TUNER_RADIO == f->type) { |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 753 | if (t->mode == T_RADIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | return 0; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 755 | t->mode = T_RADIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | tda9887_configure(t); |
| 758 | break; |
| 759 | } |
| 760 | case VIDIOC_G_TUNER: |
| 761 | { |
| 762 | static int AFC_BITS_2_kHz[] = { |
| 763 | -12500, -37500, -62500, -97500, |
| 764 | -112500, -137500, -162500, -187500, |
| 765 | 187500, 162500, 137500, 112500, |
| 766 | 97500 , 62500, 37500 , 12500 |
| 767 | }; |
| 768 | struct v4l2_tuner* tuner = arg; |
| 769 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 770 | if (t->mode == T_RADIO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | __u8 reg = 0; |
| 772 | tuner->afc=0; |
| 773 | if (1 == i2c_master_recv(&t->client,®,1)) |
| 774 | tuner->afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; |
| 775 | } |
| 776 | break; |
| 777 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 778 | case VIDIOC_S_TUNER: |
| 779 | { |
| 780 | struct v4l2_tuner* tuner = arg; |
| 781 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 782 | if (t->mode == T_RADIO) { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 783 | t->radio_mode = tuner->audmode; |
| 784 | tda9887_configure (t); |
| 785 | } |
| 786 | break; |
| 787 | } |
Hans Verkuil | 299392b | 2005-11-08 21:37:42 -0800 | [diff] [blame] | 788 | case VIDIOC_LOG_STATUS: |
| 789 | { |
| 790 | tda9887_info("Data bytes: b=%02x c=%02x e=%02x\n", t->data[1], t->data[2], t->data[3]); |
| 791 | break; |
| 792 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | default: |
| 794 | /* nothing */ |
| 795 | break; |
| 796 | } |
| 797 | return 0; |
| 798 | } |
| 799 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 800 | static int tda9887_suspend(struct device * dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 802 | struct i2c_client *c = container_of(dev, struct i2c_client, dev); |
| 803 | struct tda9887 *t = i2c_get_clientdata(c); |
| 804 | |
| 805 | tda9887_dbg("suspend\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return 0; |
| 807 | } |
| 808 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 809 | static int tda9887_resume(struct device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
| 811 | struct i2c_client *c = container_of(dev, struct i2c_client, dev); |
| 812 | struct tda9887 *t = i2c_get_clientdata(c); |
| 813 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 814 | tda9887_dbg("resume\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | tda9887_configure(t); |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | /* ----------------------------------------------------------------------- */ |
| 820 | |
| 821 | static struct i2c_driver driver = { |
| 822 | .owner = THIS_MODULE, |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 823 | .name = "i2c tda9887 driver", |
| 824 | .id = -1, /* FIXME */ |
| 825 | .flags = I2C_DF_NOTIFY, |
| 826 | .attach_adapter = tda9887_probe, |
| 827 | .detach_client = tda9887_detach, |
| 828 | .command = tda9887_command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | .driver = { |
| 830 | .suspend = tda9887_suspend, |
| 831 | .resume = tda9887_resume, |
| 832 | }, |
| 833 | }; |
| 834 | static struct i2c_client client_template = |
| 835 | { |
Jean Delvare | fae91e7 | 2005-08-15 19:57:04 +0200 | [diff] [blame] | 836 | .name = "tda9887", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | .flags = I2C_CLIENT_ALLOW_USE, |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 838 | .driver = &driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | static int __init tda9887_init_module(void) |
| 842 | { |
| 843 | return i2c_add_driver(&driver); |
| 844 | } |
| 845 | |
| 846 | static void __exit tda9887_cleanup_module(void) |
| 847 | { |
| 848 | i2c_del_driver(&driver); |
| 849 | } |
| 850 | |
| 851 | module_init(tda9887_init_module); |
| 852 | module_exit(tda9887_cleanup_module); |
| 853 | |
| 854 | /* |
| 855 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 856 | * --------------------------------------------------------------------------- |
| 857 | * Local variables: |
| 858 | * c-basic-offset: 8 |
| 859 | * End: |
| 860 | */ |