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