Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/i2c.h> |
| 4 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
| 6 | #include <linux/errno.h> |
| 7 | #include <linux/slab.h> |
| 8 | #include <linux/delay.h> |
Michael Krufky | ffbb807 | 2007-08-21 01:14:12 -0300 | [diff] [blame] | 9 | #include <linux/videodev.h> |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 10 | #include <media/v4l2-common.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <media/tuner.h> |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 12 | #include "tuner-i2c.h" |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 13 | #include "tda9887.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 | |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 21 | Used as part of several tuners |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 24 | static int tda9887_debug; |
| 25 | module_param_named(debug, tda9887_debug, int, 0644); |
| 26 | |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 27 | #define tda9887_info(fmt, arg...) do {\ |
Michael Krufky | daae589 | 2007-12-16 19:14:31 -0300 | [diff] [blame] | 28 | printk(KERN_INFO "tda9887 %d-%04x: " fmt, \ |
| 29 | i2c_adapter_id(priv->i2c_props.adap), \ |
| 30 | priv->i2c_props.addr, ##arg); } while (0) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 31 | #define tda9887_dbg(fmt, arg...) do {\ |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 32 | if (tda9887_debug) \ |
Michael Krufky | daae589 | 2007-12-16 19:14:31 -0300 | [diff] [blame] | 33 | printk(KERN_INFO "tda9887 %d-%04x: " fmt, \ |
| 34 | i2c_adapter_id(priv->i2c_props.adap), \ |
| 35 | priv->i2c_props.addr, ##arg); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 37 | struct tda9887_priv { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 38 | struct tuner_i2c_props i2c_props; |
| 39 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 40 | unsigned char data[4]; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 41 | unsigned int config; |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 42 | unsigned int mode; |
| 43 | unsigned int audmode; |
| 44 | v4l2_std_id std; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 45 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | /* ---------------------------------------------------------------------- */ |
| 48 | |
| 49 | #define UNSET (-1U) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | struct tvnorm { |
| 52 | v4l2_std_id std; |
| 53 | char *name; |
| 54 | unsigned char b; |
| 55 | unsigned char c; |
| 56 | unsigned char e; |
| 57 | }; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* ---------------------------------------------------------------------- */ |
| 60 | |
| 61 | // |
| 62 | // TDA defines |
| 63 | // |
| 64 | |
| 65 | //// first reg (b) |
| 66 | #define cVideoTrapBypassOFF 0x00 // bit b0 |
| 67 | #define cVideoTrapBypassON 0x01 // bit b0 |
| 68 | |
| 69 | #define cAutoMuteFmInactive 0x00 // bit b1 |
| 70 | #define cAutoMuteFmActive 0x02 // bit b1 |
| 71 | |
| 72 | #define cIntercarrier 0x00 // bit b2 |
| 73 | #define cQSS 0x04 // bit b2 |
| 74 | |
| 75 | #define cPositiveAmTV 0x00 // bit b3:4 |
| 76 | #define cFmRadio 0x08 // bit b3:4 |
| 77 | #define cNegativeFmTV 0x10 // bit b3:4 |
| 78 | |
| 79 | |
| 80 | #define cForcedMuteAudioON 0x20 // bit b5 |
| 81 | #define cForcedMuteAudioOFF 0x00 // bit b5 |
| 82 | |
| 83 | #define cOutputPort1Active 0x00 // bit b6 |
| 84 | #define cOutputPort1Inactive 0x40 // bit b6 |
| 85 | |
| 86 | #define cOutputPort2Active 0x00 // bit b7 |
| 87 | #define cOutputPort2Inactive 0x80 // bit b7 |
| 88 | |
| 89 | |
| 90 | //// second reg (c) |
| 91 | #define cDeemphasisOFF 0x00 // bit c5 |
| 92 | #define cDeemphasisON 0x20 // bit c5 |
| 93 | |
| 94 | #define cDeemphasis75 0x00 // bit c6 |
| 95 | #define cDeemphasis50 0x40 // bit c6 |
| 96 | |
| 97 | #define cAudioGain0 0x00 // bit c7 |
| 98 | #define cAudioGain6 0x80 // bit c7 |
| 99 | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 100 | #define cTopMask 0x1f // bit c0:4 |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 101 | #define cTopDefault 0x10 // bit c0:4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | //// third reg (e) |
| 104 | #define cAudioIF_4_5 0x00 // bit e0:1 |
| 105 | #define cAudioIF_5_5 0x01 // bit e0:1 |
| 106 | #define cAudioIF_6_0 0x02 // bit e0:1 |
| 107 | #define cAudioIF_6_5 0x03 // bit e0:1 |
| 108 | |
| 109 | |
Trent Piepho | 5e082f1 | 2007-08-03 18:32:38 -0300 | [diff] [blame] | 110 | #define cVideoIFMask 0x1c // bit e2:4 |
| 111 | /* Video IF selection in TV Mode (bit B3=0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define cVideoIF_58_75 0x00 // bit e2:4 |
| 113 | #define cVideoIF_45_75 0x04 // bit e2:4 |
| 114 | #define cVideoIF_38_90 0x08 // bit e2:4 |
| 115 | #define cVideoIF_38_00 0x0C // bit e2:4 |
| 116 | #define cVideoIF_33_90 0x10 // bit e2:4 |
| 117 | #define cVideoIF_33_40 0x14 // bit e2:4 |
| 118 | #define cRadioIF_45_75 0x18 // bit e2:4 |
| 119 | #define cRadioIF_38_90 0x1C // bit e2:4 |
| 120 | |
Trent Piepho | 5e082f1 | 2007-08-03 18:32:38 -0300 | [diff] [blame] | 121 | /* IF1 selection in Radio Mode (bit B3=1) */ |
| 122 | #define cRadioIF_33_30 0x00 // bit e2,4 (also 0x10,0x14) |
| 123 | #define cRadioIF_41_30 0x04 // bit e2,4 |
| 124 | |
| 125 | /* Output of AFC pin in radio mode when bit E7=1 */ |
| 126 | #define cRadioAGC_SIF 0x00 // bit e3 |
| 127 | #define cRadioAGC_FM 0x08 // bit e3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | #define cTunerGainNormal 0x00 // bit e5 |
| 130 | #define cTunerGainLow 0x20 // bit e5 |
| 131 | |
| 132 | #define cGating_18 0x00 // bit e6 |
| 133 | #define cGating_36 0x40 // bit e6 |
| 134 | |
| 135 | #define cAgcOutON 0x80 // bit e7 |
| 136 | #define cAgcOutOFF 0x00 // bit e7 |
| 137 | |
| 138 | /* ---------------------------------------------------------------------- */ |
| 139 | |
| 140 | static struct tvnorm tvnorms[] = { |
| 141 | { |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 142 | .std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H | V4L2_STD_PAL_N, |
| 143 | .name = "PAL-BGHN", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | .b = ( cNegativeFmTV | |
| 145 | cQSS ), |
| 146 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 147 | cDeemphasis50 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 148 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 149 | .e = ( cGating_36 | |
| 150 | cAudioIF_5_5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | cVideoIF_38_90 ), |
| 152 | },{ |
| 153 | .std = V4L2_STD_PAL_I, |
| 154 | .name = "PAL-I", |
| 155 | .b = ( cNegativeFmTV | |
| 156 | cQSS ), |
| 157 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 158 | cDeemphasis50 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 159 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 160 | .e = ( cGating_36 | |
| 161 | cAudioIF_6_0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | cVideoIF_38_90 ), |
| 163 | },{ |
| 164 | .std = V4L2_STD_PAL_DK, |
| 165 | .name = "PAL-DK", |
| 166 | .b = ( cNegativeFmTV | |
| 167 | cQSS ), |
| 168 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 169 | cDeemphasis50 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 170 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 171 | .e = ( cGating_36 | |
| 172 | cAudioIF_6_5 | |
| 173 | cVideoIF_38_90 ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | },{ |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 175 | .std = V4L2_STD_PAL_M | V4L2_STD_PAL_Nc, |
| 176 | .name = "PAL-M/Nc", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | .b = ( cNegativeFmTV | |
| 178 | cQSS ), |
| 179 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 180 | cDeemphasis75 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 181 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 182 | .e = ( cGating_36 | |
| 183 | cAudioIF_4_5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | cVideoIF_45_75 ), |
| 185 | },{ |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 186 | .std = V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H, |
| 187 | .name = "SECAM-BGH", |
| 188 | .b = ( cPositiveAmTV | |
| 189 | cQSS ), |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 190 | .c = ( cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 191 | .e = ( cGating_36 | |
| 192 | cAudioIF_5_5 | |
| 193 | cVideoIF_38_90 ), |
| 194 | },{ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | .std = V4L2_STD_SECAM_L, |
| 196 | .name = "SECAM-L", |
| 197 | .b = ( cPositiveAmTV | |
| 198 | cQSS ), |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 199 | .c = ( cTopDefault), |
Nickolay V. Shmyrev | 3375c39 | 2005-11-08 21:37:05 -0800 | [diff] [blame] | 200 | .e = ( cGating_36 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 201 | cAudioIF_6_5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | cVideoIF_38_90 ), |
| 203 | },{ |
Mauro Carvalho Chehab | f3c5987 | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 204 | .std = V4L2_STD_SECAM_LC, |
| 205 | .name = "SECAM-L'", |
| 206 | .b = ( cOutputPort2Inactive | |
| 207 | cPositiveAmTV | |
| 208 | cQSS ), |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 209 | .c = ( cTopDefault), |
Mauro Carvalho Chehab | f3c5987 | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 210 | .e = ( cGating_36 | |
| 211 | cAudioIF_6_5 | |
| 212 | cVideoIF_33_90 ), |
| 213 | },{ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | .std = V4L2_STD_SECAM_DK, |
| 215 | .name = "SECAM-DK", |
| 216 | .b = ( cNegativeFmTV | |
| 217 | cQSS ), |
| 218 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 219 | cDeemphasis50 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 220 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 221 | .e = ( cGating_36 | |
| 222 | cAudioIF_6_5 | |
| 223 | cVideoIF_38_90 ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | },{ |
Hans Verkuil | 0dfd812 | 2006-02-07 06:45:34 -0200 | [diff] [blame] | 225 | .std = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | .name = "NTSC-M", |
| 227 | .b = ( cNegativeFmTV | |
| 228 | cQSS ), |
| 229 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 230 | cDeemphasis75 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 231 | cTopDefault), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | .e = ( cGating_36 | |
| 233 | cAudioIF_4_5 | |
| 234 | cVideoIF_45_75 ), |
| 235 | },{ |
| 236 | .std = V4L2_STD_NTSC_M_JP, |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 237 | .name = "NTSC-M-JP", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | .b = ( cNegativeFmTV | |
| 239 | cQSS ), |
| 240 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 241 | cDeemphasis50 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 242 | cTopDefault), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | .e = ( cGating_36 | |
| 244 | cAudioIF_4_5 | |
| 245 | cVideoIF_58_75 ), |
| 246 | } |
| 247 | }; |
| 248 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 249 | static struct tvnorm radio_stereo = { |
| 250 | .name = "Radio Stereo", |
| 251 | .b = ( cFmRadio | |
| 252 | cQSS ), |
| 253 | .c = ( cDeemphasisOFF | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 254 | cAudioGain6 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 255 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 256 | .e = ( cTunerGainLow | |
| 257 | cAudioIF_5_5 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 258 | cRadioIF_38_90 ), |
| 259 | }; |
| 260 | |
| 261 | static struct tvnorm radio_mono = { |
| 262 | .name = "Radio Mono", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | .b = ( cFmRadio | |
| 264 | cQSS ), |
| 265 | .c = ( cDeemphasisON | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 266 | cDeemphasis75 | |
Hans Verkuil | f5b0142 | 2006-06-25 15:37:29 -0300 | [diff] [blame] | 267 | cTopDefault), |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 268 | .e = ( cTunerGainLow | |
| 269 | cAudioIF_5_5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | cRadioIF_38_90 ), |
| 271 | }; |
| 272 | |
| 273 | /* ---------------------------------------------------------------------- */ |
| 274 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 275 | static void dump_read_message(struct dvb_frontend *fe, unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 277 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | static char *afc[16] = { |
| 280 | "- 12.5 kHz", |
| 281 | "- 37.5 kHz", |
| 282 | "- 62.5 kHz", |
| 283 | "- 87.5 kHz", |
| 284 | "-112.5 kHz", |
| 285 | "-137.5 kHz", |
| 286 | "-162.5 kHz", |
| 287 | "-187.5 kHz [min]", |
| 288 | "+187.5 kHz [max]", |
| 289 | "+162.5 kHz", |
| 290 | "+137.5 kHz", |
| 291 | "+112.5 kHz", |
| 292 | "+ 87.5 kHz", |
| 293 | "+ 62.5 kHz", |
| 294 | "+ 37.5 kHz", |
| 295 | "+ 12.5 kHz", |
| 296 | }; |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 297 | tda9887_info("read: 0x%2x\n", buf[0]); |
| 298 | tda9887_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no"); |
| 299 | tda9887_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]); |
| 300 | tda9887_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low"); |
| 301 | tda9887_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out"); |
| 302 | tda9887_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 305 | static void dump_write_message(struct dvb_frontend *fe, unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 307 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | static char *sound[4] = { |
| 310 | "AM/TV", |
| 311 | "FM/radio", |
| 312 | "FM/TV", |
| 313 | "FM/radio" |
| 314 | }; |
| 315 | static char *adjust[32] = { |
| 316 | "-16", "-15", "-14", "-13", "-12", "-11", "-10", "-9", |
| 317 | "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", |
| 318 | "0", "+1", "+2", "+3", "+4", "+5", "+6", "+7", |
| 319 | "+8", "+9", "+10", "+11", "+12", "+13", "+14", "+15" |
| 320 | }; |
| 321 | static char *deemph[4] = { |
| 322 | "no", "no", "75", "50" |
| 323 | }; |
| 324 | static char *carrier[4] = { |
| 325 | "4.5 MHz", |
| 326 | "5.5 MHz", |
| 327 | "6.0 MHz", |
| 328 | "6.5 MHz / AM" |
| 329 | }; |
| 330 | static char *vif[8] = { |
| 331 | "58.75 MHz", |
| 332 | "45.75 MHz", |
| 333 | "38.9 MHz", |
| 334 | "38.0 MHz", |
| 335 | "33.9 MHz", |
| 336 | "33.4 MHz", |
| 337 | "45.75 MHz + pin13", |
| 338 | "38.9 MHz + pin13", |
| 339 | }; |
| 340 | static char *rif[4] = { |
| 341 | "44 MHz", |
| 342 | "52 MHz", |
| 343 | "52 MHz", |
| 344 | "44 MHz", |
| 345 | }; |
| 346 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 347 | tda9887_info("write: byte B 0x%02x\n",buf[1]); |
| 348 | tda9887_info(" B0 video mode : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | (buf[1] & 0x01) ? "video trap" : "sound trap"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 350 | tda9887_info(" B1 auto mute fm : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | (buf[1] & 0x02) ? "yes" : "no"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 352 | tda9887_info(" B2 carrier mode : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | (buf[1] & 0x04) ? "QSS" : "Intercarrier"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 354 | tda9887_info(" B3-4 tv sound/radio : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | sound[(buf[1] & 0x18) >> 3]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 356 | tda9887_info(" B5 force mute audio: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | (buf[1] & 0x20) ? "yes" : "no"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 358 | tda9887_info(" B6 output port 1 : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | (buf[1] & 0x40) ? "high (inactive)" : "low (active)"); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 360 | tda9887_info(" B7 output port 2 : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | (buf[1] & 0x80) ? "high (inactive)" : "low (active)"); |
| 362 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 363 | tda9887_info("write: byte C 0x%02x\n",buf[2]); |
| 364 | tda9887_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]); |
| 365 | tda9887_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]); |
| 366 | tda9887_info(" C7 audio gain : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | (buf[2] & 0x80) ? "-6" : "0"); |
| 368 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 369 | tda9887_info("write: byte E 0x%02x\n",buf[3]); |
| 370 | tda9887_info(" E0-1 sound carrier : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | carrier[(buf[3] & 0x03)]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 372 | tda9887_info(" E6 l pll gating : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | (buf[3] & 0x40) ? "36" : "13"); |
| 374 | |
| 375 | if (buf[1] & 0x08) { |
| 376 | /* radio */ |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 377 | tda9887_info(" E2-4 video if : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | rif[(buf[3] & 0x0c) >> 2]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 379 | tda9887_info(" E7 vif agc output : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | (buf[3] & 0x80) |
| 381 | ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio") |
| 382 | : "fm radio carrier afc"); |
| 383 | } else { |
| 384 | /* video */ |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 385 | tda9887_info(" E2-4 video if : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | vif[(buf[3] & 0x1c) >> 2]); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 387 | tda9887_info(" E5 tuner gain : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | (buf[3] & 0x80) |
| 389 | ? ((buf[3] & 0x20) ? "external" : "normal") |
| 390 | : ((buf[3] & 0x20) ? "minimum" : "normal")); |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 391 | tda9887_info(" E7 vif agc output : %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | (buf[3] & 0x80) |
| 393 | ? ((buf[3] & 0x20) |
| 394 | ? "pin3 port, pin22 vif agc out" |
| 395 | : "pin22 port, pin3 vif acg ext in") |
| 396 | : "pin3+pin22 port"); |
| 397 | } |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 398 | tda9887_info("--\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /* ---------------------------------------------------------------------- */ |
| 402 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 403 | static int tda9887_set_tvnorm(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 405 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | struct tvnorm *norm = NULL; |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 407 | char *buf = priv->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | int i; |
| 409 | |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 410 | if (priv->mode == V4L2_TUNER_RADIO) { |
| 411 | if (priv->audmode == V4L2_TUNER_MODE_MONO) |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 412 | norm = &radio_mono; |
| 413 | else |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 414 | norm = &radio_stereo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } else { |
| 416 | for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 417 | if (tvnorms[i].std & priv->std) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | norm = tvnorms+i; |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | if (NULL == norm) { |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 424 | tda9887_dbg("Unsupported tvnorm entry - audio muted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return -1; |
| 426 | } |
| 427 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 428 | tda9887_dbg("configure for: %s\n",norm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | buf[1] = norm->b; |
| 430 | buf[2] = norm->c; |
| 431 | buf[3] = norm->e; |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | static unsigned int port1 = UNSET; |
| 436 | static unsigned int port2 = UNSET; |
| 437 | static unsigned int qss = UNSET; |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 438 | static unsigned int adjust = UNSET; |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | module_param(port1, int, 0644); |
| 441 | module_param(port2, int, 0644); |
| 442 | module_param(qss, int, 0644); |
| 443 | module_param(adjust, int, 0644); |
| 444 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 445 | static int tda9887_set_insmod(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 447 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 448 | char *buf = priv->data; |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (UNSET != port1) { |
| 451 | if (port1) |
| 452 | buf[1] |= cOutputPort1Inactive; |
| 453 | else |
| 454 | buf[1] &= ~cOutputPort1Inactive; |
| 455 | } |
| 456 | if (UNSET != port2) { |
| 457 | if (port2) |
| 458 | buf[1] |= cOutputPort2Inactive; |
| 459 | else |
| 460 | buf[1] &= ~cOutputPort2Inactive; |
| 461 | } |
| 462 | |
| 463 | if (UNSET != qss) { |
| 464 | if (qss) |
| 465 | buf[1] |= cQSS; |
| 466 | else |
| 467 | buf[1] &= ~cQSS; |
| 468 | } |
| 469 | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 470 | if (adjust >= 0x00 && adjust < 0x20) { |
| 471 | buf[2] &= ~cTopMask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | buf[2] |= adjust; |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 477 | static int tda9887_do_config(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 479 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 480 | char *buf = priv->data; |
| 481 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 482 | if (priv->config & TDA9887_PORT1_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | buf[1] &= ~cOutputPort1Inactive; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 484 | if (priv->config & TDA9887_PORT1_INACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | buf[1] |= cOutputPort1Inactive; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 486 | if (priv->config & TDA9887_PORT2_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | buf[1] &= ~cOutputPort2Inactive; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 488 | if (priv->config & TDA9887_PORT2_INACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | buf[1] |= cOutputPort2Inactive; |
| 490 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 491 | if (priv->config & TDA9887_QSS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | buf[1] |= cQSS; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 493 | if (priv->config & TDA9887_INTERCARRIER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | buf[1] &= ~cQSS; |
| 495 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 496 | if (priv->config & TDA9887_AUTOMUTE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | buf[1] |= cAutoMuteFmActive; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 498 | if (priv->config & TDA9887_DEEMPHASIS_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | buf[2] &= ~0x60; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 500 | switch (priv->config & TDA9887_DEEMPHASIS_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | case TDA9887_DEEMPHASIS_NONE: |
| 502 | buf[2] |= cDeemphasisOFF; |
| 503 | break; |
| 504 | case TDA9887_DEEMPHASIS_50: |
| 505 | buf[2] |= cDeemphasisON | cDeemphasis50; |
| 506 | break; |
| 507 | case TDA9887_DEEMPHASIS_75: |
| 508 | buf[2] |= cDeemphasisON | cDeemphasis75; |
| 509 | break; |
| 510 | } |
| 511 | } |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 512 | if (priv->config & TDA9887_TOP_SET) { |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 513 | buf[2] &= ~cTopMask; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 514 | buf[2] |= (priv->config >> 8) & cTopMask; |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 515 | } |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 516 | if ((priv->config & TDA9887_INTERCARRIER_NTSC) && |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 517 | (priv->std & V4L2_STD_NTSC)) |
Nickolay V. Shmyrev | 3ae1adc | 2005-11-08 21:37:39 -0800 | [diff] [blame] | 518 | buf[1] &= ~cQSS; |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 519 | if (priv->config & TDA9887_GATING_18) |
Trent Piepho | d7304de | 2006-08-24 22:43:45 -0300 | [diff] [blame] | 520 | buf[3] &= ~cGating_36; |
Mauro Carvalho Chehab | cefccc8 | 2006-12-04 08:31:35 -0300 | [diff] [blame] | 521 | |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 522 | if (priv->mode == V4L2_TUNER_RADIO) { |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 523 | if (priv->config & TDA9887_RIF_41_3) { |
Trent Piepho | 5e082f1 | 2007-08-03 18:32:38 -0300 | [diff] [blame] | 524 | buf[3] &= ~cVideoIFMask; |
| 525 | buf[3] |= cRadioIF_41_30; |
| 526 | } |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 527 | if (priv->config & TDA9887_GAIN_NORMAL) |
Trent Piepho | 5e082f1 | 2007-08-03 18:32:38 -0300 | [diff] [blame] | 528 | buf[3] &= ~cTunerGainLow; |
Mauro Carvalho Chehab | cefccc8 | 2006-12-04 08:31:35 -0300 | [diff] [blame] | 529 | } |
| 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | /* ---------------------------------------------------------------------- */ |
| 535 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 536 | static int tda9887_status(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 538 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | unsigned char buf[1]; |
| 540 | int rc; |
| 541 | |
| 542 | memset(buf,0,sizeof(buf)); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 543 | if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1))) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 544 | tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 545 | dump_read_message(fe, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 549 | static void tda9887_configure(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 551 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | int rc; |
| 553 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 554 | memset(priv->data,0,sizeof(priv->data)); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 555 | tda9887_set_tvnorm(fe); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 556 | |
Hans Verkuil | f98c55e | 2006-01-09 15:25:18 -0200 | [diff] [blame] | 557 | /* A note on the port settings: |
| 558 | These settings tend to depend on the specifics of the board. |
| 559 | By default they are set to inactive (bit value 1) by this driver, |
| 560 | overwriting any changes made by the tvnorm. This means that it |
| 561 | is the responsibility of the module using the tda9887 to set |
| 562 | these values in case of changes in the tvnorm. |
| 563 | In many cases port 2 should be made active (0) when selecting |
| 564 | SECAM-L, and port 2 should remain inactive (1) for SECAM-L'. |
| 565 | |
| 566 | For the other standards the tda9887 application note says that |
| 567 | the ports should be set to active (0), but, again, that may |
| 568 | differ depending on the precise hardware configuration. |
| 569 | */ |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 570 | priv->data[1] |= cOutputPort1Inactive; |
| 571 | priv->data[1] |= cOutputPort2Inactive; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 572 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 573 | tda9887_do_config(fe); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 574 | tda9887_set_insmod(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 576 | if (priv->mode == T_STANDBY) |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 577 | priv->data[1] |= cForcedMuteAudioON; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 578 | |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 579 | tda9887_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n", |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 580 | priv->data[1],priv->data[2],priv->data[3]); |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 581 | if (tda9887_debug > 1) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 582 | dump_write_message(fe, priv->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 584 | if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4))) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 585 | 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] | 586 | |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 587 | if (tda9887_debug > 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | msleep_interruptible(1000); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 589 | tda9887_status(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* ---------------------------------------------------------------------- */ |
| 594 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 595 | static void tda9887_tuner_status(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 597 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 598 | tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", |
| 599 | priv->data[1], priv->data[2], priv->data[3]); |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 600 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 602 | static int tda9887_get_afc(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 603 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 604 | struct tda9887_priv *priv = fe->analog_demod_priv; |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 605 | static int AFC_BITS_2_kHz[] = { |
| 606 | -12500, -37500, -62500, -97500, |
| 607 | -112500, -137500, -162500, -187500, |
| 608 | 187500, 162500, 137500, 112500, |
| 609 | 97500 , 62500, 37500 , 12500 |
| 610 | }; |
| 611 | int afc=0; |
| 612 | __u8 reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 614 | if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,®,1)) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 615 | afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 616 | |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 617 | return afc; |
| 618 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 619 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 620 | static void tda9887_standby(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 621 | { |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 622 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 623 | |
| 624 | priv->mode = T_STANDBY; |
| 625 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 626 | tda9887_configure(fe); |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 627 | } |
Hans Verkuil | 4eb0c14 | 2005-11-08 21:37:18 -0800 | [diff] [blame] | 628 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 629 | static void tda9887_set_params(struct dvb_frontend *fe, |
| 630 | struct analog_parameters *params) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 631 | { |
Michael Krufky | 91c9d4a | 2007-12-16 20:05:00 -0300 | [diff] [blame^] | 632 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 633 | |
| 634 | priv->mode = params->mode; |
| 635 | priv->audmode = params->audmode; |
| 636 | priv->std = params->std; |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 637 | tda9887_configure(fe); |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 638 | } |
| 639 | |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 640 | static int tda9887_set_config(struct dvb_frontend *fe, void *priv_cfg) |
| 641 | { |
| 642 | struct tda9887_priv *priv = fe->analog_demod_priv; |
| 643 | |
| 644 | priv->config = *(unsigned int *)priv_cfg; |
| 645 | tda9887_configure(fe); |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 650 | static void tda9887_release(struct dvb_frontend *fe) |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 651 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 652 | kfree(fe->analog_demod_priv); |
| 653 | fe->analog_demod_priv = NULL; |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 654 | } |
| 655 | |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 656 | static struct analog_tuner_ops tda9887_tuner_ops = { |
Michael Krufky | a55db8c | 2007-12-09 13:52:51 -0300 | [diff] [blame] | 657 | .info = { |
| 658 | .name = "TDA9887", |
| 659 | }, |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 660 | .set_params = tda9887_set_params, |
Michael Krufky | 9af596e | 2007-06-06 16:15:48 -0300 | [diff] [blame] | 661 | .standby = tda9887_standby, |
| 662 | .tuner_status = tda9887_tuner_status, |
| 663 | .get_afc = tda9887_get_afc, |
| 664 | .release = tda9887_release, |
Michael Krufky | 710401b | 2007-12-16 19:53:32 -0300 | [diff] [blame] | 665 | .set_config = tda9887_set_config, |
Michael Krufky | 9af596e | 2007-06-06 16:15:48 -0300 | [diff] [blame] | 666 | }; |
| 667 | |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 668 | int tda9887_attach(struct tuner *t) |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 669 | { |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 670 | struct tda9887_priv *priv = NULL; |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 671 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 672 | priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); |
| 673 | if (priv == NULL) |
| 674 | return -ENOMEM; |
Michael Krufky | 16f2916 | 2007-10-21 15:22:25 -0300 | [diff] [blame] | 675 | t->fe.analog_demod_priv = priv; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 676 | |
Hans Verkuil | 1cba97d7 | 2007-09-14 05:13:54 -0300 | [diff] [blame] | 677 | priv->i2c_props.addr = t->i2c->addr; |
| 678 | priv->i2c_props.adap = t->i2c->adapter; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 679 | |
Hans Verkuil | 1cba97d7 | 2007-09-14 05:13:54 -0300 | [diff] [blame] | 680 | strlcpy(t->i2c->name, "tda9887", sizeof(t->i2c->name)); |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 681 | |
Hans Verkuil | 1cba97d7 | 2007-09-14 05:13:54 -0300 | [diff] [blame] | 682 | tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c->addr, |
| 683 | t->i2c->driver->driver.name); |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 684 | |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 685 | t->fe.ops.analog_demod_ops = &tda9887_tuner_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | return 0; |
| 688 | } |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 689 | EXPORT_SYMBOL_GPL(tda9887_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Michael Krufky | 5ef4730 | 2007-10-27 02:17:19 -0300 | [diff] [blame] | 691 | MODULE_LICENSE("GPL"); |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* |
| 694 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 695 | * --------------------------------------------------------------------------- |
| 696 | * Local variables: |
| 697 | * c-basic-offset: 8 |
| 698 | * End: |
| 699 | */ |