Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * i2c tv tuner chip device driver |
| 4 | * controls all those simple 4-control-bytes style tuners. |
| 5 | */ |
| 6 | #include <linux/delay.h> |
| 7 | #include <linux/i2c.h> |
| 8 | #include <linux/videodev.h> |
| 9 | #include <media/tuner.h> |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 10 | #include <media/v4l2-common.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Mauro Carvalho Chehab | 5c07db0 | 2006-01-09 15:25:11 -0200 | [diff] [blame] | 12 | static int offset = 0; |
Mauro Carvalho Chehab | 4d98816 | 2006-08-12 21:59:19 -0300 | [diff] [blame] | 13 | module_param(offset, int, 0664); |
Mauro Carvalho Chehab | 5c07db0 | 2006-01-09 15:25:11 -0200 | [diff] [blame] | 14 | MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner"); |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | /* ---------------------------------------------------------------------- */ |
| 17 | |
| 18 | /* tv standard selection for Temic 4046 FM5 |
| 19 | this value takes the low bits of control byte 2 |
| 20 | from datasheet Rev.01, Feb.00 |
| 21 | standard BG I L L2 D |
| 22 | picture IF 38.9 38.9 38.9 33.95 38.9 |
| 23 | sound 1 33.4 32.9 32.4 40.45 32.4 |
| 24 | sound 2 33.16 |
| 25 | NICAM 33.05 32.348 33.05 33.05 |
| 26 | */ |
| 27 | #define TEMIC_SET_PAL_I 0x05 |
| 28 | #define TEMIC_SET_PAL_DK 0x09 |
| 29 | #define TEMIC_SET_PAL_L 0x0a // SECAM ? |
| 30 | #define TEMIC_SET_PAL_L2 0x0b // change IF ! |
| 31 | #define TEMIC_SET_PAL_BG 0x0c |
| 32 | |
| 33 | /* tv tuner system standard selection for Philips FQ1216ME |
| 34 | this value takes the low bits of control byte 2 |
| 35 | from datasheet "1999 Nov 16" (supersedes "1999 Mar 23") |
| 36 | standard BG DK I L L` |
| 37 | picture carrier 38.90 38.90 38.90 38.90 33.95 |
| 38 | colour 34.47 34.47 34.47 34.47 38.38 |
| 39 | sound 1 33.40 32.40 32.90 32.40 40.45 |
| 40 | sound 2 33.16 - - - - |
| 41 | NICAM 33.05 33.05 32.35 33.05 39.80 |
| 42 | */ |
| 43 | #define PHILIPS_SET_PAL_I 0x01 /* Bit 2 always zero !*/ |
| 44 | #define PHILIPS_SET_PAL_BGDK 0x09 |
| 45 | #define PHILIPS_SET_PAL_L2 0x0a |
| 46 | #define PHILIPS_SET_PAL_L 0x0b |
| 47 | |
| 48 | /* system switching for Philips FI1216MF MK2 |
| 49 | from datasheet "1996 Jul 09", |
| 50 | standard BG L L' |
| 51 | picture carrier 38.90 38.90 33.95 |
| 52 | colour 34.47 34.37 38.38 |
| 53 | sound 1 33.40 32.40 40.45 |
| 54 | sound 2 33.16 - - |
| 55 | NICAM 33.05 33.05 39.80 |
| 56 | */ |
| 57 | #define PHILIPS_MF_SET_BG 0x01 /* Bit 2 must be zero, Bit 3 is system output */ |
| 58 | #define PHILIPS_MF_SET_PAL_L 0x03 // France |
| 59 | #define PHILIPS_MF_SET_PAL_L2 0x02 // L' |
| 60 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 61 | /* Control byte */ |
| 62 | |
| 63 | #define TUNER_RATIO_MASK 0x06 /* Bit cb1:cb2 */ |
| 64 | #define TUNER_RATIO_SELECT_50 0x00 |
| 65 | #define TUNER_RATIO_SELECT_32 0x02 |
| 66 | #define TUNER_RATIO_SELECT_166 0x04 |
| 67 | #define TUNER_RATIO_SELECT_62 0x06 |
| 68 | |
| 69 | #define TUNER_CHARGE_PUMP 0x40 /* Bit cb6 */ |
| 70 | |
| 71 | /* Status byte */ |
| 72 | |
| 73 | #define TUNER_POR 0x80 |
| 74 | #define TUNER_FL 0x40 |
| 75 | #define TUNER_MODE 0x38 |
| 76 | #define TUNER_AFC 0x07 |
| 77 | #define TUNER_SIGNAL 0x07 |
| 78 | #define TUNER_STEREO 0x10 |
| 79 | |
| 80 | #define TUNER_PLL_LOCKED 0x40 |
| 81 | #define TUNER_STEREO_MK3 0x04 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* ---------------------------------------------------------------------- */ |
| 84 | |
| 85 | static int tuner_getstatus(struct i2c_client *c) |
| 86 | { |
| 87 | unsigned char byte; |
| 88 | |
| 89 | if (1 != i2c_master_recv(c,&byte,1)) |
| 90 | return 0; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return byte; |
| 93 | } |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static int tuner_signal(struct i2c_client *c) |
| 96 | { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 97 | return (tuner_getstatus(c) & TUNER_SIGNAL) << 13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static int tuner_stereo(struct i2c_client *c) |
| 101 | { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 102 | int stereo, status; |
| 103 | struct tuner *t = i2c_get_clientdata(c); |
| 104 | |
| 105 | status = tuner_getstatus (c); |
| 106 | |
| 107 | switch (t->type) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 108 | case TUNER_PHILIPS_FM1216ME_MK3: |
Trent Piepho | 657de3c | 2006-06-20 00:30:57 -0300 | [diff] [blame] | 109 | case TUNER_PHILIPS_FM1236_MK3: |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 110 | case TUNER_PHILIPS_FM1256_IH3: |
Hans Verkuil | 122b5db | 2006-12-03 06:45:07 -0300 | [diff] [blame] | 111 | case TUNER_LG_NTSC_TAPE: |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 112 | stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); |
| 113 | break; |
| 114 | default: |
| 115 | stereo = status & TUNER_STEREO; |
| 116 | } |
| 117 | |
| 118 | return stereo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* ---------------------------------------------------------------------- */ |
| 123 | |
| 124 | static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 125 | { |
| 126 | struct tuner *t = i2c_get_clientdata(c); |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 127 | u8 config, cb, tuneraddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | u16 div; |
| 129 | struct tunertype *tun; |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 130 | u8 buffer[4]; |
Michael Krufky | 7b0ac9c | 2006-01-13 14:10:25 -0200 | [diff] [blame] | 131 | int rc, IFPCoff, i, j; |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 132 | enum param_type desired_type; |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 133 | struct tuner_params *params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | tun = &tuners[t->type]; |
Michael Krufky | 7b0ac9c | 2006-01-13 14:10:25 -0200 | [diff] [blame] | 136 | |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 137 | /* IFPCoff = Video Intermediate Frequency - Vif: |
| 138 | 940 =16*58.75 NTSC/J (Japan) |
| 139 | 732 =16*45.75 M/N STD |
| 140 | 704 =16*44 ATSC (at DVB code) |
| 141 | 632 =16*39.50 I U.K. |
| 142 | 622.4=16*38.90 B/G D/K I, L STD |
| 143 | 592 =16*37.00 D China |
| 144 | 590 =16.36.875 B Australia |
| 145 | 543.2=16*33.95 L' STD |
| 146 | 171.2=16*10.70 FM Radio (at set_radio_freq) |
| 147 | */ |
| 148 | |
| 149 | if (t->std == V4L2_STD_NTSC_M_JP) { |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 150 | IFPCoff = 940; |
| 151 | desired_type = TUNER_PARAM_TYPE_NTSC; |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 152 | } else if ((t->std & V4L2_STD_MN) && |
| 153 | !(t->std & ~V4L2_STD_MN)) { |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 154 | IFPCoff = 732; |
| 155 | desired_type = TUNER_PARAM_TYPE_NTSC; |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 156 | } else if (t->std == V4L2_STD_SECAM_LC) { |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 157 | IFPCoff = 543; |
| 158 | desired_type = TUNER_PARAM_TYPE_SECAM; |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 159 | } else { |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 160 | IFPCoff = 623; |
| 161 | desired_type = TUNER_PARAM_TYPE_PAL; |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 162 | } |
| 163 | |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 164 | for (j = 0; j < tun->count-1; j++) { |
| 165 | if (desired_type != tun->params[j].type) |
| 166 | continue; |
| 167 | break; |
| 168 | } |
Michael Krufky | 8f1a58d | 2006-02-07 06:25:39 -0200 | [diff] [blame] | 169 | /* use default tuner_params if desired_type not available */ |
Michael Krufky | 15207b2 | 2006-02-07 06:25:40 -0200 | [diff] [blame] | 170 | if (desired_type != tun->params[j].type) { |
| 171 | tuner_dbg("IFPCoff = %d: tuner_params undefined for tuner %d\n", |
| 172 | IFPCoff,t->type); |
Michael Krufky | 8f1a58d | 2006-02-07 06:25:39 -0200 | [diff] [blame] | 173 | j = 0; |
Michael Krufky | 15207b2 | 2006-02-07 06:25:40 -0200 | [diff] [blame] | 174 | } |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 175 | params = &tun->params[j]; |
Michael Krufky | 8f1a58d | 2006-02-07 06:25:39 -0200 | [diff] [blame] | 176 | |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 177 | for (i = 0; i < params->count; i++) { |
| 178 | if (freq > params->ranges[i].limit) |
Michael Krufky | 90200d2 | 2006-01-09 15:25:38 -0200 | [diff] [blame] | 179 | continue; |
| 180 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 182 | if (i == params->count) { |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 183 | tuner_dbg("TV frequency out of range (%d > %d)", |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 184 | freq, params->ranges[i - 1].limit); |
| 185 | freq = params->ranges[--i].limit; |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 186 | } |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 187 | config = params->ranges[i].config; |
| 188 | cb = params->ranges[i].cb; |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 189 | /* i == 0 -> VHF_LO |
| 190 | * i == 1 -> VHF_HI |
| 191 | * i == 2 -> UHF */ |
Michael Krufky | bd0d0f5 | 2006-02-07 06:25:35 -0200 | [diff] [blame] | 192 | tuner_dbg("tv: param %d, range %d\n",j,i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Michael Krufky | 5f59418 | 2006-02-07 06:25:33 -0200 | [diff] [blame] | 194 | div=freq + IFPCoff + offset; |
| 195 | |
| 196 | tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n", |
| 197 | freq / 16, freq % 16 * 100 / 16, |
| 198 | IFPCoff / 16, IFPCoff % 16 * 100 / 16, |
| 199 | offset / 16, offset % 16 * 100 / 16, |
| 200 | div); |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | /* tv norm specific stuff for multi-norm tuners */ |
| 203 | switch (t->type) { |
| 204 | case TUNER_PHILIPS_SECAM: // FI1216MF |
| 205 | /* 0x01 -> ??? no change ??? */ |
| 206 | /* 0x02 -> PAL BDGHI / SECAM L */ |
| 207 | /* 0x04 -> ??? PAL others / SECAM others ??? */ |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 208 | cb &= ~0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (t->std & V4L2_STD_SECAM) |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 210 | cb |= 0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | break; |
| 212 | |
| 213 | case TUNER_TEMIC_4046FM5: |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 214 | cb &= ~0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | if (t->std & V4L2_STD_PAL_BG) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 217 | cb |= TEMIC_SET_PAL_BG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | } else if (t->std & V4L2_STD_PAL_I) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 220 | cb |= TEMIC_SET_PAL_I; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | } else if (t->std & V4L2_STD_PAL_DK) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 223 | cb |= TEMIC_SET_PAL_DK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | } else if (t->std & V4L2_STD_SECAM_L) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 226 | cb |= TEMIC_SET_PAL_L; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | } |
| 229 | break; |
| 230 | |
| 231 | case TUNER_PHILIPS_FQ1216ME: |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 232 | cb &= ~0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (t->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 235 | cb |= PHILIPS_SET_PAL_BGDK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | } else if (t->std & V4L2_STD_PAL_I) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 238 | cb |= PHILIPS_SET_PAL_I; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | } else if (t->std & V4L2_STD_SECAM_L) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 241 | cb |= PHILIPS_SET_PAL_L; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | } |
| 244 | break; |
| 245 | |
| 246 | case TUNER_PHILIPS_ATSC: |
| 247 | /* 0x00 -> ATSC antenna input 1 */ |
| 248 | /* 0x01 -> ATSC antenna input 2 */ |
| 249 | /* 0x02 -> NTSC antenna input 1 */ |
| 250 | /* 0x03 -> NTSC antenna input 2 */ |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 251 | cb &= ~0x03; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (!(t->std & V4L2_STD_ATSC)) |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 253 | cb |= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* FIXME: input */ |
| 255 | break; |
| 256 | |
| 257 | case TUNER_MICROTUNE_4042FI5: |
| 258 | /* Set the charge pump for fast tuning */ |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 259 | config |= TUNER_CHARGE_PUMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | break; |
Kirk Lapray | e976f937 | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 261 | |
| 262 | case TUNER_PHILIPS_TUV1236D: |
| 263 | /* 0x40 -> ATSC antenna input 1 */ |
| 264 | /* 0x48 -> ATSC antenna input 2 */ |
| 265 | /* 0x00 -> NTSC antenna input 1 */ |
| 266 | /* 0x08 -> NTSC antenna input 2 */ |
Kirk Lapray | fde6d31 | 2005-11-08 21:38:18 -0800 | [diff] [blame] | 267 | buffer[0] = 0x14; |
| 268 | buffer[1] = 0x00; |
| 269 | buffer[2] = 0x17; |
| 270 | buffer[3] = 0x00; |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 271 | cb &= ~0x40; |
Kirk Lapray | fde6d31 | 2005-11-08 21:38:18 -0800 | [diff] [blame] | 272 | if (t->std & V4L2_STD_ATSC) { |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 273 | cb |= 0x40; |
Kirk Lapray | fde6d31 | 2005-11-08 21:38:18 -0800 | [diff] [blame] | 274 | buffer[1] = 0x04; |
| 275 | } |
| 276 | /* set to the correct mode (analog or digital) */ |
Kirk Lapray | fde6d31 | 2005-11-08 21:38:18 -0800 | [diff] [blame] | 277 | tuneraddr = c->addr; |
| 278 | c->addr = 0x0a; |
| 279 | if (2 != (rc = i2c_master_send(c,&buffer[0],2))) |
| 280 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
| 281 | if (2 != (rc = i2c_master_send(c,&buffer[2],2))) |
| 282 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
| 283 | c->addr = tuneraddr; |
Kirk Lapray | e976f937 | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 284 | /* FIXME: input */ |
| 285 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 288 | if (params->cb_first_if_lower_freq && div < t->last_div) { |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 289 | buffer[0] = config; |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 290 | buffer[1] = cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | buffer[2] = (div>>8) & 0x7f; |
| 292 | buffer[3] = div & 0xff; |
| 293 | } else { |
| 294 | buffer[0] = (div>>8) & 0x7f; |
| 295 | buffer[1] = div & 0xff; |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 296 | buffer[2] = config; |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 297 | buffer[3] = cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 299 | t->last_div = div; |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 300 | if (params->has_tda9887) { |
| 301 | int config = 0; |
| 302 | int is_secam_l = (t->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) && |
| 303 | !(t->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)); |
| 304 | |
| 305 | if (t->std == V4L2_STD_SECAM_LC) { |
| 306 | if (params->port1_active ^ params->port1_invert_for_secam_lc) |
| 307 | config |= TDA9887_PORT1_ACTIVE; |
| 308 | if (params->port2_active ^ params->port2_invert_for_secam_lc) |
| 309 | config |= TDA9887_PORT2_ACTIVE; |
| 310 | } |
| 311 | else { |
| 312 | if (params->port1_active) |
| 313 | config |= TDA9887_PORT1_ACTIVE; |
| 314 | if (params->port2_active) |
| 315 | config |= TDA9887_PORT2_ACTIVE; |
| 316 | } |
| 317 | if (params->intercarrier_mode) |
| 318 | config |= TDA9887_INTERCARRIER; |
| 319 | if (is_secam_l) { |
| 320 | if (i == 0 && params->default_top_secam_low) |
| 321 | config |= TDA9887_TOP(params->default_top_secam_low); |
| 322 | else if (i == 1 && params->default_top_secam_mid) |
| 323 | config |= TDA9887_TOP(params->default_top_secam_mid); |
| 324 | else if (params->default_top_secam_high) |
| 325 | config |= TDA9887_TOP(params->default_top_secam_high); |
| 326 | } |
| 327 | else { |
| 328 | if (i == 0 && params->default_top_low) |
| 329 | config |= TDA9887_TOP(params->default_top_low); |
| 330 | else if (i == 1 && params->default_top_mid) |
| 331 | config |= TDA9887_TOP(params->default_top_mid); |
| 332 | else if (params->default_top_high) |
| 333 | config |= TDA9887_TOP(params->default_top_high); |
| 334 | } |
Trent Piepho | d7304de | 2006-08-24 22:43:45 -0300 | [diff] [blame] | 335 | if (params->default_pll_gating_18) |
| 336 | config |= TDA9887_GATING_18; |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 337 | i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); |
| 338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", |
| 340 | buffer[0],buffer[1],buffer[2],buffer[3]); |
| 341 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 342 | if (4 != (rc = i2c_master_send(c,buffer,4))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
| 344 | |
Michael Krufky | d9cd2d9 | 2006-07-17 17:15:26 -0300 | [diff] [blame] | 345 | switch (t->type) { |
| 346 | case TUNER_LG_TDVS_H06XF: |
| 347 | /* Set the Auxiliary Byte. */ |
| 348 | buffer[0] = buffer[2]; |
| 349 | buffer[0] &= ~0x20; |
| 350 | buffer[0] |= 0x18; |
| 351 | buffer[1] = 0x20; |
| 352 | tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]); |
| 353 | |
| 354 | if (2 != (rc = i2c_master_send(c,buffer,2))) |
| 355 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
| 356 | break; |
| 357 | case TUNER_MICROTUNE_4042FI5: |
| 358 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | // FIXME - this may also work for other tuners |
| 360 | unsigned long timeout = jiffies + msecs_to_jiffies(1); |
| 361 | u8 status_byte = 0; |
| 362 | |
| 363 | /* Wait until the PLL locks */ |
| 364 | for (;;) { |
| 365 | if (time_after(jiffies,timeout)) |
| 366 | return; |
| 367 | if (1 != (rc = i2c_master_recv(c,&status_byte,1))) { |
| 368 | tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); |
| 369 | break; |
| 370 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 371 | if (status_byte & TUNER_PLL_LOCKED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | break; |
| 373 | udelay(10); |
| 374 | } |
| 375 | |
| 376 | /* Set the charge pump for optimized phase noise figure */ |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 377 | config &= ~TUNER_CHARGE_PUMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | buffer[0] = (div>>8) & 0x7f; |
| 379 | buffer[1] = div & 0xff; |
Michael Krufky | 3fc46d3 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 380 | buffer[2] = config; |
Michael Krufky | ab66b22 | 2006-01-23 17:11:11 -0200 | [diff] [blame] | 381 | buffer[3] = cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", |
Michael Krufky | d9cd2d9 | 2006-07-17 17:15:26 -0300 | [diff] [blame] | 383 | buffer[0],buffer[1],buffer[2],buffer[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | if (4 != (rc = i2c_master_send(c,buffer,4))) |
| 386 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
Michael Krufky | d9cd2d9 | 2006-07-17 17:15:26 -0300 | [diff] [blame] | 387 | break; |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
| 392 | static void default_set_radio_freq(struct i2c_client *c, unsigned int freq) |
| 393 | { |
| 394 | struct tunertype *tun; |
| 395 | struct tuner *t = i2c_get_clientdata(c); |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 396 | u8 buffer[4]; |
| 397 | u16 div; |
Michael Krufky | 7b0ac9c | 2006-01-13 14:10:25 -0200 | [diff] [blame] | 398 | int rc, j; |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 399 | enum param_type desired_type = TUNER_PARAM_TYPE_RADIO; |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 400 | struct tuner_params *params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 402 | tun = &tuners[t->type]; |
Michael Krufky | 476d63d | 2006-02-07 06:25:34 -0200 | [diff] [blame] | 403 | |
| 404 | for (j = 0; j < tun->count-1; j++) { |
| 405 | if (desired_type != tun->params[j].type) |
| 406 | continue; |
| 407 | break; |
| 408 | } |
Michael Krufky | 8f1a58d | 2006-02-07 06:25:39 -0200 | [diff] [blame] | 409 | /* use default tuner_params if desired_type not available */ |
| 410 | if (desired_type != tun->params[j].type) |
| 411 | j = 0; |
Michael Krufky | 7b0ac9c | 2006-01-13 14:10:25 -0200 | [diff] [blame] | 412 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 413 | div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */ |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 414 | params = &tun->params[j]; |
| 415 | buffer[2] = (params->ranges[0].config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | switch (t->type) { |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 418 | case TUNER_TENA_9533_DI: |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 419 | case TUNER_YMEC_TVF_5533MF: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 420 | tuner_dbg ("This tuner doesn't have FM. Most cards has a TEA5767 for FM\n"); |
| 421 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | case TUNER_PHILIPS_FM1216ME_MK3: |
| 423 | case TUNER_PHILIPS_FM1236_MK3: |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 424 | case TUNER_PHILIPS_FMD1216ME_MK3: |
Hans Verkuil | 122b5db | 2006-12-03 06:45:07 -0300 | [diff] [blame] | 425 | case TUNER_LG_NTSC_TAPE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | buffer[3] = 0x19; |
| 427 | break; |
Mauro Carvalho Chehab | efcf55c | 2006-03-09 11:17:43 -0300 | [diff] [blame] | 428 | case TUNER_TNF_5335MF: |
| 429 | buffer[3] = 0x11; |
| 430 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | case TUNER_PHILIPS_FM1256_IH3: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 432 | div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | buffer[3] = 0x19; |
| 434 | break; |
| 435 | case TUNER_LG_PAL_FM: |
| 436 | buffer[3] = 0xa5; |
| 437 | break; |
Mauro Carvalho Chehab | 33ac6b5 | 2005-09-09 13:03:56 -0700 | [diff] [blame] | 438 | case TUNER_MICROTUNE_4049FM5: |
| 439 | div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */ |
| 440 | buffer[3] = 0xa4; |
| 441 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | default: |
| 443 | buffer[3] = 0xa4; |
| 444 | break; |
| 445 | } |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 446 | if (params->cb_first_if_lower_freq && div < t->last_div) { |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 447 | buffer[0] = buffer[2]; |
| 448 | buffer[1] = buffer[3]; |
| 449 | buffer[2] = (div>>8) & 0x7f; |
| 450 | buffer[3] = div & 0xff; |
| 451 | } else { |
| 452 | buffer[0] = (div>>8) & 0x7f; |
| 453 | buffer[1] = div & 0xff; |
| 454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n", |
| 457 | buffer[0],buffer[1],buffer[2],buffer[3]); |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 458 | t->last_div = div; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 460 | if (params->has_tda9887) { |
| 461 | int config = 0; |
| 462 | if (params->port1_active && !params->port1_fm_high_sensitivity) |
| 463 | config |= TDA9887_PORT1_ACTIVE; |
| 464 | if (params->port2_active && !params->port2_fm_high_sensitivity) |
| 465 | config |= TDA9887_PORT2_ACTIVE; |
| 466 | if (params->intercarrier_mode) |
| 467 | config |= TDA9887_INTERCARRIER; |
| 468 | /* if (params->port1_set_for_fm_mono) |
| 469 | config &= ~TDA9887_PORT1_ACTIVE;*/ |
Mauro Carvalho Chehab | 483deb0 | 2006-12-04 08:31:38 -0300 | [diff] [blame^] | 470 | if (params->fm_gain_normal) |
| 471 | config |= TDA9887_GAIN_NORMAL; |
Hans Verkuil | ba8fc39 | 2006-06-25 15:34:39 -0300 | [diff] [blame] | 472 | i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); |
| 473 | } |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 474 | if (4 != (rc = i2c_master_send(c,buffer,4))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
| 476 | } |
| 477 | |
| 478 | int default_tuner_init(struct i2c_client *c) |
| 479 | { |
| 480 | struct tuner *t = i2c_get_clientdata(c); |
| 481 | |
| 482 | tuner_info("type set to %d (%s)\n", |
| 483 | t->type, tuners[t->type].name); |
| 484 | strlcpy(c->name, tuners[t->type].name, sizeof(c->name)); |
| 485 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 486 | t->set_tv_freq = default_set_tv_freq; |
| 487 | t->set_radio_freq = default_set_radio_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | t->has_signal = tuner_signal; |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 489 | t->is_stereo = tuner_stereo; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 490 | t->standby = NULL; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 497 | * --------------------------------------------------------------------------- |
| 498 | * Local variables: |
| 499 | * c-basic-offset: 8 |
| 500 | * End: |
| 501 | */ |