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