Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 2 | |
| 3 | i2c tv tuner chip device driver |
| 4 | controls the philips tda8290+75 tuner chip combo. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/i2c.h> |
| 22 | #include <linux/videodev.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <media/tuner.h> |
| 25 | |
| 26 | /* ---------------------------------------------------------------------- */ |
| 27 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 28 | struct tda827x_data { |
| 29 | u32 lomax; |
| 30 | u8 spd; |
| 31 | u8 bs; |
| 32 | u8 bp; |
| 33 | u8 cp; |
| 34 | u8 gc3; |
| 35 | u8 div1p5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 38 | /* Note lomax entry is lo / 62500 */ |
| 39 | |
| 40 | static struct tda827x_data tda827x_analog[] = { |
| 41 | { .lomax = 992, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 62 MHz */ |
| 42 | { .lomax = 1056, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 66 MHz */ |
| 43 | { .lomax = 1216, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 76 MHz */ |
| 44 | { .lomax = 1344, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 84 MHz */ |
| 45 | { .lomax = 1488, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 93 MHz */ |
| 46 | { .lomax = 1568, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 98 MHz */ |
| 47 | { .lomax = 1744, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 109 MHz */ |
| 48 | { .lomax = 1968, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 123 MHz */ |
| 49 | { .lomax = 2128, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 133 MHz */ |
| 50 | { .lomax = 2416, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 151 MHz */ |
| 51 | { .lomax = 2464, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 154 MHz */ |
| 52 | { .lomax = 2896, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 181 MHz */ |
| 53 | { .lomax = 2960, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 185 MHz */ |
| 54 | { .lomax = 3472, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 217 MHz */ |
| 55 | { .lomax = 3904, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 244 MHz */ |
| 56 | { .lomax = 4240, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 265 MHz */ |
| 57 | { .lomax = 4832, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 302 MHz */ |
| 58 | { .lomax = 5184, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 324 MHz */ |
| 59 | { .lomax = 5920, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 370 MHz */ |
| 60 | { .lomax = 7264, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 454 MHz */ |
| 61 | { .lomax = 7888, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 493 MHz */ |
| 62 | { .lomax = 8480, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 530 MHz */ |
| 63 | { .lomax = 8864, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 554 MHz */ |
| 64 | { .lomax = 9664, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 604 MHz */ |
| 65 | { .lomax = 11088, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 696 MHz */ |
| 66 | { .lomax = 11840, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 740 MHz */ |
| 67 | { .lomax = 13120, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 820 MHz */ |
| 68 | { .lomax = 13840, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 865 MHz */ |
| 69 | { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 72 | static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 74 | unsigned char tuner_reg[8]; |
| 75 | unsigned char reg2[2]; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 76 | u32 N; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 77 | int i; |
| 78 | struct tuner *t = i2c_get_clientdata(c); |
| 79 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 81 | if (t->mode == V4L2_TUNER_RADIO) |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 82 | freq = freq / 1000; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 83 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 84 | N = freq + ifc; |
| 85 | i = 0; |
| 86 | while (tda827x_analog[i].lomax < N) { |
| 87 | if(tda827x_analog[i + 1].lomax == 0) |
| 88 | break; |
| 89 | i++; |
| 90 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 91 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 92 | N = N << tda827x_analog[i].spd; |
| 93 | |
| 94 | tuner_reg[0] = 0; |
| 95 | tuner_reg[1] = (unsigned char)(N>>8); |
| 96 | tuner_reg[2] = (unsigned char) N; |
| 97 | tuner_reg[3] = 0x40; |
| 98 | tuner_reg[4] = 0x52 + (t->tda827x_lpsel << 5); |
| 99 | tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) + |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 100 | (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 101 | tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4); |
| 102 | tuner_reg[7] = 0x8f; |
| 103 | |
| 104 | msg.buf = tuner_reg; |
| 105 | msg.len = 8; |
| 106 | i2c_transfer(c->adapter, &msg, 1); |
| 107 | |
| 108 | msg.buf= reg2; |
| 109 | msg.len = 2; |
| 110 | reg2[0] = 0x80; |
| 111 | reg2[1] = 0; |
| 112 | i2c_transfer(c->adapter, &msg, 1); |
| 113 | |
| 114 | reg2[0] = 0x60; |
| 115 | reg2[1] = 0xbf; |
| 116 | i2c_transfer(c->adapter, &msg, 1); |
| 117 | |
| 118 | reg2[0] = 0x30; |
| 119 | reg2[1] = tuner_reg[4] + 0x80; |
| 120 | i2c_transfer(c->adapter, &msg, 1); |
| 121 | |
| 122 | msleep(1); |
| 123 | reg2[0] = 0x30; |
| 124 | reg2[1] = tuner_reg[4] + 4; |
| 125 | i2c_transfer(c->adapter, &msg, 1); |
| 126 | |
| 127 | msleep(1); |
| 128 | reg2[0] = 0x30; |
| 129 | reg2[1] = tuner_reg[4]; |
| 130 | i2c_transfer(c->adapter, &msg, 1); |
| 131 | |
| 132 | msleep(550); |
| 133 | reg2[0] = 0x30; |
| 134 | reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ; |
| 135 | i2c_transfer(c->adapter, &msg, 1); |
| 136 | |
| 137 | reg2[0] = 0x60; |
| 138 | reg2[1] = 0x7f; |
| 139 | i2c_transfer(c->adapter, &msg, 1); |
| 140 | |
| 141 | reg2[0] = 0x80; |
| 142 | reg2[1] = 0x08; // Vsync en |
| 143 | i2c_transfer(c->adapter, &msg, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 146 | static void tda827x_agcf(struct i2c_client *c) |
| 147 | { |
| 148 | struct tuner *t = i2c_get_clientdata(c); |
| 149 | unsigned char data[] = {0x80, 0x0c}; |
| 150 | struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data, |
| 151 | .flags = 0, .len = 2}; |
| 152 | i2c_transfer(c->adapter, &msg, 1); |
| 153 | } |
| 154 | |
| 155 | /* ---------------------------------------------------------------------- */ |
| 156 | |
| 157 | struct tda827xa_data { |
| 158 | u32 lomax; |
| 159 | u8 svco; |
| 160 | u8 spd; |
| 161 | u8 scr; |
| 162 | u8 sbs; |
| 163 | u8 gc3; |
| 164 | }; |
| 165 | |
| 166 | static struct tda827xa_data tda827xa_analog[] = { |
| 167 | { .lomax = 910, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, /* 56.875 MHz */ |
| 168 | { .lomax = 1076, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 67.25 MHz */ |
| 169 | { .lomax = 1300, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 81.25 MHz */ |
| 170 | { .lomax = 1560, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 97.5 MHz */ |
| 171 | { .lomax = 1820, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1}, /* 113.75 MHz */ |
| 172 | { .lomax = 2152, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 134.5 MHz */ |
| 173 | { .lomax = 2464, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 154 MHz */ |
| 174 | { .lomax = 2600, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 162.5 MHz */ |
| 175 | { .lomax = 2928, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 183 MHz */ |
| 176 | { .lomax = 3120, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1}, /* 195 MHz */ |
| 177 | { .lomax = 3640, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3}, /* 227.5 MHz */ |
| 178 | { .lomax = 4304, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3}, /* 269 MHz */ |
| 179 | { .lomax = 5200, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1}, /* 325 MHz */ |
| 180 | { .lomax = 6240, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 390 MHz */ |
| 181 | { .lomax = 7280, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 455 MHz */ |
| 182 | { .lomax = 8320, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 520 MHz */ |
| 183 | { .lomax = 8608, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, /* 538 MHz */ |
| 184 | { .lomax = 8864, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 554 MHz */ |
| 185 | { .lomax = 9920, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 620 MHz */ |
| 186 | { .lomax = 10400, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 650 MHz */ |
| 187 | { .lomax = 11200, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 700 MHz */ |
| 188 | { .lomax = 12480, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 780 MHz */ |
| 189 | { .lomax = 13120, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 820 MHz */ |
| 190 | { .lomax = 13920, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 870 MHz */ |
| 191 | { .lomax = 14576, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0}, /* 911 MHz */ |
| 192 | { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */ |
| 193 | }; |
| 194 | |
| 195 | static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
| 196 | { |
| 197 | unsigned char tuner_reg[14]; |
| 198 | unsigned char reg2[2]; |
| 199 | u32 N; |
| 200 | int i; |
| 201 | struct tuner *t = i2c_get_clientdata(c); |
| 202 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0}; |
| 203 | |
| 204 | if (t->mode == V4L2_TUNER_RADIO) |
| 205 | freq = freq / 1000; |
| 206 | |
| 207 | N = freq + ifc; |
| 208 | i = 0; |
| 209 | while (tda827xa_analog[i].lomax < N) { |
| 210 | if(tda827xa_analog[i + 1].lomax == 0) |
| 211 | break; |
| 212 | i++; |
| 213 | } |
| 214 | |
| 215 | N = N << tda827xa_analog[i].spd; |
| 216 | |
| 217 | tuner_reg[0] = 0; |
| 218 | tuner_reg[1] = (unsigned char)(N>>8); |
| 219 | tuner_reg[2] = (unsigned char) N; |
| 220 | tuner_reg[3] = 0; |
| 221 | tuner_reg[4] = 0x16; |
| 222 | tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) + |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 223 | tda827xa_analog[i].sbs; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 224 | tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4); |
| 225 | tuner_reg[7] = 0x0c; |
| 226 | tuner_reg[8] = 4; |
| 227 | tuner_reg[9] = 0x20; |
| 228 | tuner_reg[10] = 0xff; |
| 229 | tuner_reg[11] = 0xe0; |
| 230 | tuner_reg[12] = 0; |
| 231 | tuner_reg[13] = 0x39 + (t->tda827x_lpsel << 1); |
| 232 | |
| 233 | msg.buf = tuner_reg; |
| 234 | msg.len = 14; |
| 235 | i2c_transfer(c->adapter, &msg, 1); |
| 236 | |
| 237 | msg.buf= reg2; |
| 238 | msg.len = 2; |
| 239 | reg2[0] = 0x60; |
| 240 | reg2[1] = 0x3c; |
| 241 | i2c_transfer(c->adapter, &msg, 1); |
| 242 | |
| 243 | reg2[0] = 0xa0; |
| 244 | reg2[1] = 0xc0; |
| 245 | i2c_transfer(c->adapter, &msg, 1); |
| 246 | |
| 247 | msleep(2); |
| 248 | reg2[0] = 0x30; |
| 249 | reg2[1] = 0x10 + tda827xa_analog[i].scr; |
| 250 | i2c_transfer(c->adapter, &msg, 1); |
| 251 | |
| 252 | msleep(550); |
| 253 | reg2[0] = 0x50; |
| 254 | reg2[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); |
| 255 | i2c_transfer(c->adapter, &msg, 1); |
| 256 | |
| 257 | reg2[0] = 0x80; |
| 258 | reg2[1] = 0x28; |
| 259 | i2c_transfer(c->adapter, &msg, 1); |
| 260 | |
| 261 | reg2[0] = 0xb0; |
| 262 | reg2[1] = 0x01; |
| 263 | i2c_transfer(c->adapter, &msg, 1); |
| 264 | |
| 265 | reg2[0] = 0xc0; |
| 266 | reg2[1] = 0x19 + (t->tda827x_lpsel << 1); |
| 267 | i2c_transfer(c->adapter, &msg, 1); |
| 268 | } |
| 269 | |
| 270 | static void tda827xa_agcf(struct i2c_client *c) |
| 271 | { |
| 272 | struct tuner *t = i2c_get_clientdata(c); |
| 273 | unsigned char data[] = {0x80, 0x2c}; |
| 274 | struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data, |
| 275 | .flags = 0, .len = 2}; |
| 276 | i2c_transfer(c->adapter, &msg, 1); |
| 277 | } |
| 278 | |
| 279 | /*---------------------------------------------------------------------*/ |
| 280 | |
| 281 | static void tda8290_i2c_bridge(struct i2c_client *c, int close) |
| 282 | { |
| 283 | unsigned char enable[2] = { 0x21, 0xC0 }; |
| 284 | unsigned char disable[2] = { 0x21, 0x80 }; |
| 285 | unsigned char *msg; |
| 286 | if(close) { |
| 287 | msg = enable; |
| 288 | i2c_master_send(c, msg, 2); |
| 289 | /* let the bridge stabilize */ |
| 290 | msleep(20); |
| 291 | } else { |
| 292 | msg = disable; |
| 293 | i2c_master_send(c, msg, 2); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /*---------------------------------------------------------------------*/ |
| 298 | |
| 299 | static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
| 300 | { |
| 301 | struct tuner *t = i2c_get_clientdata(c); |
| 302 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 303 | unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode }; |
| 304 | unsigned char expert_mode[] = { 0x01, 0x80 }; |
| 305 | unsigned char gainset_off[] = { 0x28, 0x14 }; |
| 306 | unsigned char if_agc_spd[] = { 0x0f, 0x88 }; |
| 307 | unsigned char adc_head_6[] = { 0x05, 0x04 }; |
| 308 | unsigned char adc_head_9[] = { 0x05, 0x02 }; |
| 309 | unsigned char adc_head_12[] = { 0x05, 0x01 }; |
| 310 | unsigned char pll_bw_nom[] = { 0x0d, 0x47 }; |
| 311 | unsigned char pll_bw_low[] = { 0x0d, 0x27 }; |
| 312 | unsigned char gainset_2[] = { 0x28, 0x64 }; |
| 313 | unsigned char agc_rst_on[] = { 0x0e, 0x0b }; |
| 314 | unsigned char agc_rst_off[] = { 0x0e, 0x09 }; |
| 315 | unsigned char if_agc_set[] = { 0x0f, 0x81 }; |
| 316 | unsigned char addr_adc_sat = 0x1a; |
| 317 | unsigned char addr_agc_stat = 0x1d; |
| 318 | unsigned char addr_pll_stat = 0x1b; |
| 319 | unsigned char adc_sat, agc_stat, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 320 | pll_stat; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 321 | |
| 322 | i2c_master_send(c, easy_mode, 2); |
| 323 | i2c_master_send(c, soft_reset, 2); |
| 324 | msleep(1); |
| 325 | |
| 326 | i2c_master_send(c, expert_mode, 2); |
| 327 | i2c_master_send(c, gainset_off, 2); |
| 328 | i2c_master_send(c, if_agc_spd, 2); |
| 329 | if (t->tda8290_easy_mode & 0x60) |
| 330 | i2c_master_send(c, adc_head_9, 2); |
| 331 | else |
| 332 | i2c_master_send(c, adc_head_6, 2); |
| 333 | i2c_master_send(c, pll_bw_nom, 2); |
| 334 | |
| 335 | tda8290_i2c_bridge(c, 1); |
| 336 | if (t->tda827x_ver != 0) |
| 337 | tda827xa_tune(c, ifc, freq); |
| 338 | else |
| 339 | tda827x_tune(c, ifc, freq); |
| 340 | /* adjust headroom resp. gain */ |
| 341 | i2c_master_send(c, &addr_adc_sat, 1); |
| 342 | i2c_master_recv(c, &adc_sat, 1); |
| 343 | i2c_master_send(c, &addr_agc_stat, 1); |
| 344 | i2c_master_recv(c, &agc_stat, 1); |
| 345 | i2c_master_send(c, &addr_pll_stat, 1); |
| 346 | i2c_master_recv(c, &pll_stat, 1); |
| 347 | if (pll_stat & 0x80) |
| 348 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); |
| 349 | else |
| 350 | tuner_dbg("tda8290 not locked, no signal?\n"); |
| 351 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat <20))) { |
| 352 | tuner_dbg("adjust gain, step 1. Agc: %d\n", agc_stat); |
| 353 | i2c_master_send(c, gainset_2, 2); |
| 354 | msleep(100); |
| 355 | i2c_master_send(c, &addr_agc_stat, 1); |
| 356 | i2c_master_recv(c, &agc_stat, 1); |
| 357 | i2c_master_send(c, &addr_pll_stat, 1); |
| 358 | i2c_master_recv(c, &pll_stat, 1); |
| 359 | if ((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 360 | tuner_dbg("adjust gain, step 2. Agc: %d\n", agc_stat); |
| 361 | if (t->tda827x_ver != 0) |
| 362 | tda827xa_agcf(c); |
| 363 | else |
| 364 | tda827x_agcf(c); |
| 365 | msleep(100); |
| 366 | i2c_master_send(c, &addr_agc_stat, 1); |
| 367 | i2c_master_recv(c, &agc_stat, 1); |
| 368 | i2c_master_send(c, &addr_pll_stat, 1); |
| 369 | i2c_master_recv(c, &pll_stat, 1); |
| 370 | if((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 371 | tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); |
| 372 | i2c_master_send(c, adc_head_12, 2); |
| 373 | i2c_master_send(c, pll_bw_low, 2); |
| 374 | msleep(100); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /* l/ l' deadlock? */ |
| 380 | if(t->tda8290_easy_mode & 0x60) { |
| 381 | i2c_master_send(c, &addr_adc_sat, 1); |
| 382 | i2c_master_recv(c, &adc_sat, 1); |
| 383 | i2c_master_send(c, &addr_pll_stat, 1); |
| 384 | i2c_master_recv(c, &pll_stat, 1); |
| 385 | if ((adc_sat > 20) || !(pll_stat & 0x80)) { |
| 386 | i2c_master_send(c, agc_rst_on, 2); |
| 387 | msleep(40); |
| 388 | i2c_master_send(c, agc_rst_off, 2); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | tda8290_i2c_bridge(c, 0); |
| 393 | i2c_master_send(c, if_agc_set, 2); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /*---------------------------------------------------------------------*/ |
| 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC) |
| 401 | #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B) |
| 402 | #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H) |
| 403 | #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK) |
| 404 | |
| 405 | static void set_audio(struct tuner *t) |
| 406 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 407 | t->tda827x_lpsel = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 409 | if (t->std & V4L2_STD_MN) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 410 | t->sgIF = 92; |
| 411 | t->tda8290_easy_mode = 0x01; |
| 412 | t->tda827x_lpsel = 1; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 413 | } else if (t->std & V4L2_STD_B) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 414 | t->sgIF = 108; |
| 415 | t->tda8290_easy_mode = 0x02; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 416 | } else if (t->std & V4L2_STD_GH) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 417 | t->sgIF = 124; |
| 418 | t->tda8290_easy_mode = 0x04; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 419 | } else if (t->std & V4L2_STD_PAL_I) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 420 | t->sgIF = 124; |
| 421 | t->tda8290_easy_mode = 0x08; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 422 | } else if (t->std & V4L2_STD_DK) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 423 | t->sgIF = 124; |
| 424 | t->tda8290_easy_mode = 0x10; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 425 | } else if (t->std & V4L2_STD_SECAM_L) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 426 | t->sgIF = 124; |
| 427 | t->tda8290_easy_mode = 0x20; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 432 | { |
| 433 | struct tuner *t = i2c_get_clientdata(c); |
| 434 | |
| 435 | set_audio(t); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 436 | tda8290_tune(c, t->sgIF, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) |
| 440 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 441 | /* if frequency is 5.5 MHz */ |
| 442 | tda8290_tune(c, 88, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static int has_signal(struct i2c_client *c) |
| 446 | { |
| 447 | unsigned char i2c_get_afc[1] = { 0x1B }; |
| 448 | unsigned char afc = 0; |
| 449 | |
| 450 | i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); |
| 451 | i2c_master_recv(c, &afc, 1); |
| 452 | return (afc & 0x80)? 65535:0; |
| 453 | } |
| 454 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 455 | /*---------------------------------------------------------------------*/ |
| 456 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 457 | static void standby(struct i2c_client *c) |
| 458 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 459 | struct tuner *t = i2c_get_clientdata(c); |
| 460 | unsigned char cb1[] = { 0x30, 0xD0 }; |
| 461 | unsigned char tda8290_standby[] = { 0x00, 0x02 }; |
| 462 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; |
| 463 | |
| 464 | tda8290_i2c_bridge(c, 1); |
| 465 | if (t->tda827x_ver != 0) |
| 466 | cb1[1] = 0x90; |
| 467 | i2c_transfer(c->adapter, &msg, 1); |
| 468 | tda8290_i2c_bridge(c, 0); |
| 469 | i2c_master_send(c, tda8290_standby, 2); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 472 | |
| 473 | static void tda8290_init_if(struct i2c_client *c) |
| 474 | { |
| 475 | unsigned char set_VS[] = { 0x30, 0x6F }; |
| 476 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
| 477 | |
| 478 | i2c_master_send(c, set_VS, 2); |
| 479 | i2c_master_send(c, set_GP01_CF, 2); |
| 480 | } |
| 481 | |
| 482 | static void tda8290_init_tuner(struct i2c_client *c) |
| 483 | { |
| 484 | struct tuner *t = i2c_get_clientdata(c); |
| 485 | unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 486 | 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 487 | unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 488 | 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 489 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 490 | .buf=tda8275_init, .len = 14}; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 491 | if (t->tda827x_ver != 0) |
| 492 | msg.buf = tda8275a_init; |
| 493 | |
| 494 | tda8290_i2c_bridge(c, 1); |
| 495 | i2c_transfer(c->adapter, &msg, 1); |
| 496 | tda8290_i2c_bridge(c, 0); |
| 497 | } |
| 498 | |
| 499 | /*---------------------------------------------------------------------*/ |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | int tda8290_init(struct i2c_client *c) |
| 502 | { |
| 503 | struct tuner *t = i2c_get_clientdata(c); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 504 | u8 data; |
| 505 | int i, ret, tuners_found; |
| 506 | u32 tuner_addrs; |
| 507 | struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 509 | tda8290_i2c_bridge(c, 1); |
| 510 | /* probe for tuner chip */ |
| 511 | tuners_found = 0; |
| 512 | tuner_addrs = 0; |
| 513 | for (i=0x60; i<= 0x63; i++) { |
| 514 | msg.addr = i; |
| 515 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 516 | if (ret == 1) { |
| 517 | tuners_found++; |
| 518 | tuner_addrs = (tuner_addrs << 8) + i; |
| 519 | } |
| 520 | } |
| 521 | /* if there is more than one tuner, we expect the right one is |
| 522 | behind the bridge and we choose the highest address that doesn't |
| 523 | give a response now |
| 524 | */ |
| 525 | tda8290_i2c_bridge(c, 0); |
| 526 | if(tuners_found > 1) |
| 527 | for (i = 0; i < tuners_found; i++) { |
| 528 | msg.addr = tuner_addrs & 0xff; |
| 529 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 530 | if(ret == 1) |
| 531 | tuner_addrs = tuner_addrs >> 8; |
| 532 | else |
| 533 | break; |
| 534 | } |
| 535 | if (tuner_addrs == 0) { |
| 536 | tuner_addrs = 0x61; |
| 537 | tuner_info ("could not clearly identify tuner address, defaulting to %x\n", |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame^] | 538 | tuner_addrs); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 539 | } else { |
| 540 | tuner_addrs = tuner_addrs & 0xff; |
| 541 | tuner_info ("setting tuner address to %x\n", tuner_addrs); |
| 542 | } |
| 543 | t->tda827x_addr = tuner_addrs; |
| 544 | msg.addr = tuner_addrs; |
| 545 | |
| 546 | tda8290_i2c_bridge(c, 1); |
| 547 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 548 | if( ret != 1) |
| 549 | tuner_warn ("TDA827x access failed!\n"); |
| 550 | if ((data & 0x3c) == 0) { |
| 551 | strlcpy(c->name, "tda8290+75", sizeof(c->name)); |
| 552 | t->tda827x_ver = 0; |
| 553 | } else { |
| 554 | strlcpy(c->name, "tda8290+75a", sizeof(c->name)); |
| 555 | t->tda827x_ver = 2; |
| 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | tuner_info("tuner: type set to %s\n", c->name); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | t->tv_freq = set_tv_freq; |
| 560 | t->radio_freq = set_radio_freq; |
| 561 | t->has_signal = has_signal; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 562 | t->standby = standby; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 563 | t->tda827x_lpsel = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 565 | tda8290_init_tuner(c); |
| 566 | tda8290_init_if(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 572 | * --------------------------------------------------------------------------- |
| 573 | * Local variables: |
| 574 | * c-basic-offset: 8 |
| 575 | * End: |
| 576 | */ |