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; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 138 | reg2[1] = 0x3f; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 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 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 195 | static void tda827xa_lna_gain(struct i2c_client *c, int high) |
| 196 | { |
| 197 | struct tuner *t = i2c_get_clientdata(c); |
| 198 | unsigned char buf[] = {0x22, 0x01}; |
| 199 | int arg; |
| 200 | struct i2c_msg msg = {.addr = c->addr, .flags = 0, .buf = buf, .len = sizeof(buf)}; |
| 201 | if (t->config) { |
| 202 | if (high) |
| 203 | tuner_dbg("setting LNA to high gain\n"); |
| 204 | else |
| 205 | tuner_dbg("setting LNA to low gain\n"); |
| 206 | } |
| 207 | switch (t->config) { |
| 208 | case 0: /* no LNA */ |
| 209 | break; |
| 210 | case 1: /* switch is GPIO 0 of tda8290 */ |
| 211 | case 2: |
| 212 | /* turn Vsync on */ |
| 213 | if (t->std & V4L2_STD_MN) |
Hartmut Hackmann | cfeb883 | 2007-04-27 12:31:17 -0300 | [diff] [blame] | 214 | arg = 1; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 215 | else |
Hartmut Hackmann | cfeb883 | 2007-04-27 12:31:17 -0300 | [diff] [blame] | 216 | arg = 0; |
| 217 | if (t->tuner_callback) |
| 218 | t->tuner_callback(c->adapter->algo_data, 1, arg); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 219 | buf[1] = high ? 0 : 1; |
| 220 | if (t->config == 2) |
| 221 | buf[1] = high ? 1 : 0; |
| 222 | i2c_transfer(c->adapter, &msg, 1); |
| 223 | break; |
| 224 | case 3: /* switch with GPIO of saa713x */ |
Hartmut Hackmann | cfeb883 | 2007-04-27 12:31:17 -0300 | [diff] [blame] | 225 | if (t->tuner_callback) |
| 226 | t->tuner_callback(c->adapter->algo_data, 0, high); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | } |
| 230 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 231 | static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
| 232 | { |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 233 | unsigned char tuner_reg[11]; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 234 | u32 N; |
| 235 | int i; |
| 236 | struct tuner *t = i2c_get_clientdata(c); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 237 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0, .buf = tuner_reg}; |
| 238 | |
| 239 | tda827xa_lna_gain( c, 1); |
| 240 | msleep(10); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 241 | |
| 242 | if (t->mode == V4L2_TUNER_RADIO) |
| 243 | freq = freq / 1000; |
| 244 | |
| 245 | N = freq + ifc; |
| 246 | i = 0; |
| 247 | while (tda827xa_analog[i].lomax < N) { |
| 248 | if(tda827xa_analog[i + 1].lomax == 0) |
| 249 | break; |
| 250 | i++; |
| 251 | } |
| 252 | |
| 253 | N = N << tda827xa_analog[i].spd; |
| 254 | |
| 255 | tuner_reg[0] = 0; |
| 256 | tuner_reg[1] = (unsigned char)(N>>8); |
| 257 | tuner_reg[2] = (unsigned char) N; |
| 258 | tuner_reg[3] = 0; |
| 259 | tuner_reg[4] = 0x16; |
| 260 | 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] | 261 | tda827xa_analog[i].sbs; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 262 | tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 263 | tuner_reg[7] = 0x1c; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 264 | tuner_reg[8] = 4; |
| 265 | tuner_reg[9] = 0x20; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 266 | tuner_reg[10] = 0x00; |
| 267 | msg.len = 11; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 268 | i2c_transfer(c->adapter, &msg, 1); |
| 269 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 270 | tuner_reg[0] = 0x90; |
| 271 | tuner_reg[1] = 0xff; |
| 272 | tuner_reg[2] = 0xe0; |
| 273 | tuner_reg[3] = 0; |
| 274 | tuner_reg[4] = 0x99 + (t->tda827x_lpsel << 1); |
| 275 | msg.len = 5; |
| 276 | i2c_transfer(c->adapter, &msg, 1); |
| 277 | |
| 278 | tuner_reg[0] = 0xa0; |
| 279 | tuner_reg[1] = 0xc0; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 280 | msg.len = 2; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 281 | i2c_transfer(c->adapter, &msg, 1); |
| 282 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 283 | tuner_reg[0] = 0x30; |
| 284 | tuner_reg[1] = 0x10 + tda827xa_analog[i].scr; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 285 | i2c_transfer(c->adapter, &msg, 1); |
| 286 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 287 | msg.flags = I2C_M_RD; |
| 288 | i2c_transfer(c->adapter, &msg, 1); |
| 289 | msg.flags = 0; |
| 290 | tuner_reg[1] >>= 4; |
| 291 | tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]); |
| 292 | if (tuner_reg[1] < 1) |
| 293 | tda827xa_lna_gain( c, 0); |
| 294 | |
| 295 | msleep(100); |
| 296 | tuner_reg[0] = 0x60; |
| 297 | tuner_reg[1] = 0x3c; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 298 | i2c_transfer(c->adapter, &msg, 1); |
| 299 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 300 | msleep(163); |
| 301 | tuner_reg[0] = 0x50; |
| 302 | tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 303 | i2c_transfer(c->adapter, &msg, 1); |
| 304 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 305 | tuner_reg[0] = 0x80; |
| 306 | tuner_reg[1] = 0x28; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 307 | i2c_transfer(c->adapter, &msg, 1); |
| 308 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 309 | tuner_reg[0] = 0xb0; |
| 310 | tuner_reg[1] = 0x01; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 311 | i2c_transfer(c->adapter, &msg, 1); |
| 312 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 313 | tuner_reg[0] = 0xc0; |
| 314 | tuner_reg[1] = 0x19 + (t->tda827x_lpsel << 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 315 | i2c_transfer(c->adapter, &msg, 1); |
| 316 | } |
| 317 | |
| 318 | static void tda827xa_agcf(struct i2c_client *c) |
| 319 | { |
| 320 | struct tuner *t = i2c_get_clientdata(c); |
| 321 | unsigned char data[] = {0x80, 0x2c}; |
| 322 | struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data, |
| 323 | .flags = 0, .len = 2}; |
| 324 | i2c_transfer(c->adapter, &msg, 1); |
| 325 | } |
| 326 | |
| 327 | /*---------------------------------------------------------------------*/ |
| 328 | |
| 329 | static void tda8290_i2c_bridge(struct i2c_client *c, int close) |
| 330 | { |
| 331 | unsigned char enable[2] = { 0x21, 0xC0 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 332 | unsigned char disable[2] = { 0x21, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 333 | unsigned char *msg; |
| 334 | if(close) { |
| 335 | msg = enable; |
| 336 | i2c_master_send(c, msg, 2); |
| 337 | /* let the bridge stabilize */ |
| 338 | msleep(20); |
| 339 | } else { |
| 340 | msg = disable; |
| 341 | i2c_master_send(c, msg, 2); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /*---------------------------------------------------------------------*/ |
| 346 | |
| 347 | static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
| 348 | { |
| 349 | struct tuner *t = i2c_get_clientdata(c); |
| 350 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 351 | unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode }; |
| 352 | unsigned char expert_mode[] = { 0x01, 0x80 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 353 | unsigned char agc_out_on[] = { 0x02, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 354 | unsigned char gainset_off[] = { 0x28, 0x14 }; |
| 355 | unsigned char if_agc_spd[] = { 0x0f, 0x88 }; |
| 356 | unsigned char adc_head_6[] = { 0x05, 0x04 }; |
| 357 | unsigned char adc_head_9[] = { 0x05, 0x02 }; |
| 358 | unsigned char adc_head_12[] = { 0x05, 0x01 }; |
| 359 | unsigned char pll_bw_nom[] = { 0x0d, 0x47 }; |
| 360 | unsigned char pll_bw_low[] = { 0x0d, 0x27 }; |
| 361 | unsigned char gainset_2[] = { 0x28, 0x64 }; |
| 362 | unsigned char agc_rst_on[] = { 0x0e, 0x0b }; |
| 363 | unsigned char agc_rst_off[] = { 0x0e, 0x09 }; |
| 364 | unsigned char if_agc_set[] = { 0x0f, 0x81 }; |
| 365 | unsigned char addr_adc_sat = 0x1a; |
| 366 | unsigned char addr_agc_stat = 0x1d; |
| 367 | unsigned char addr_pll_stat = 0x1b; |
| 368 | unsigned char adc_sat, agc_stat, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 369 | pll_stat; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 370 | int i; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 371 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 372 | tuner_dbg("tda827xa config is 0x%02x\n", t->config); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 373 | i2c_master_send(c, easy_mode, 2); |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 374 | i2c_master_send(c, agc_out_on, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 375 | i2c_master_send(c, soft_reset, 2); |
| 376 | msleep(1); |
| 377 | |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 378 | expert_mode[1] = t->tda8290_easy_mode + 0x80; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 379 | i2c_master_send(c, expert_mode, 2); |
| 380 | i2c_master_send(c, gainset_off, 2); |
| 381 | i2c_master_send(c, if_agc_spd, 2); |
| 382 | if (t->tda8290_easy_mode & 0x60) |
| 383 | i2c_master_send(c, adc_head_9, 2); |
| 384 | else |
| 385 | i2c_master_send(c, adc_head_6, 2); |
| 386 | i2c_master_send(c, pll_bw_nom, 2); |
| 387 | |
| 388 | tda8290_i2c_bridge(c, 1); |
| 389 | if (t->tda827x_ver != 0) |
| 390 | tda827xa_tune(c, ifc, freq); |
| 391 | else |
| 392 | tda827x_tune(c, ifc, freq); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 393 | for (i = 0; i < 3; i++) { |
| 394 | i2c_master_send(c, &addr_pll_stat, 1); |
| 395 | i2c_master_recv(c, &pll_stat, 1); |
| 396 | if (pll_stat & 0x80) { |
| 397 | i2c_master_send(c, &addr_adc_sat, 1); |
| 398 | i2c_master_recv(c, &adc_sat, 1); |
| 399 | i2c_master_send(c, &addr_agc_stat, 1); |
| 400 | i2c_master_recv(c, &agc_stat, 1); |
| 401 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); |
| 402 | break; |
| 403 | } else { |
| 404 | tuner_dbg("tda8290 not locked, no signal?\n"); |
| 405 | msleep(100); |
| 406 | } |
| 407 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 408 | /* adjust headroom resp. gain */ |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 409 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { |
| 410 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", |
| 411 | agc_stat, adc_sat, pll_stat & 0x80); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 412 | i2c_master_send(c, gainset_2, 2); |
| 413 | msleep(100); |
| 414 | i2c_master_send(c, &addr_agc_stat, 1); |
| 415 | i2c_master_recv(c, &agc_stat, 1); |
| 416 | i2c_master_send(c, &addr_pll_stat, 1); |
| 417 | i2c_master_recv(c, &pll_stat, 1); |
| 418 | if ((agc_stat > 115) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 419 | tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", |
| 420 | agc_stat, pll_stat & 0x80); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 421 | if (t->tda827x_ver != 0) |
| 422 | tda827xa_agcf(c); |
| 423 | else |
| 424 | tda827x_agcf(c); |
| 425 | msleep(100); |
| 426 | i2c_master_send(c, &addr_agc_stat, 1); |
| 427 | i2c_master_recv(c, &agc_stat, 1); |
| 428 | i2c_master_send(c, &addr_pll_stat, 1); |
| 429 | i2c_master_recv(c, &pll_stat, 1); |
| 430 | if((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 431 | tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); |
| 432 | i2c_master_send(c, adc_head_12, 2); |
| 433 | i2c_master_send(c, pll_bw_low, 2); |
| 434 | msleep(100); |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* l/ l' deadlock? */ |
| 440 | if(t->tda8290_easy_mode & 0x60) { |
| 441 | i2c_master_send(c, &addr_adc_sat, 1); |
| 442 | i2c_master_recv(c, &adc_sat, 1); |
| 443 | i2c_master_send(c, &addr_pll_stat, 1); |
| 444 | i2c_master_recv(c, &pll_stat, 1); |
| 445 | if ((adc_sat > 20) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 446 | tuner_dbg("trying to resolve SECAM L deadlock\n"); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 447 | i2c_master_send(c, agc_rst_on, 2); |
| 448 | msleep(40); |
| 449 | i2c_master_send(c, agc_rst_off, 2); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | tda8290_i2c_bridge(c, 0); |
| 454 | i2c_master_send(c, if_agc_set, 2); |
| 455 | return 0; |
| 456 | } |
| 457 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 458 | /*---------------------------------------------------------------------*/ |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | static void set_audio(struct tuner *t) |
| 461 | { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 462 | char* mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 464 | t->tda827x_lpsel = 0; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 465 | if (t->std & V4L2_STD_MN) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 466 | t->sgIF = 92; |
| 467 | t->tda8290_easy_mode = 0x01; |
| 468 | t->tda827x_lpsel = 1; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 469 | mode = "MN"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 470 | } else if (t->std & V4L2_STD_B) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 471 | t->sgIF = 108; |
| 472 | t->tda8290_easy_mode = 0x02; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 473 | mode = "B"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 474 | } else if (t->std & V4L2_STD_GH) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 475 | t->sgIF = 124; |
| 476 | t->tda8290_easy_mode = 0x04; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 477 | mode = "GH"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 478 | } else if (t->std & V4L2_STD_PAL_I) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 479 | t->sgIF = 124; |
| 480 | t->tda8290_easy_mode = 0x08; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 481 | mode = "I"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 482 | } else if (t->std & V4L2_STD_DK) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 483 | t->sgIF = 124; |
| 484 | t->tda8290_easy_mode = 0x10; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 485 | mode = "DK"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 486 | } else if (t->std & V4L2_STD_SECAM_L) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 487 | t->sgIF = 124; |
| 488 | t->tda8290_easy_mode = 0x20; |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 489 | mode = "L"; |
Hartmut Hackmann | 70146cf | 2005-11-13 16:07:58 -0800 | [diff] [blame] | 490 | } else if (t->std & V4L2_STD_SECAM_LC) { |
| 491 | t->sgIF = 20; |
| 492 | t->tda8290_easy_mode = 0x40; |
| 493 | mode = "LC"; |
Hartmut Hackmann | e65ec75 | 2007-03-22 20:58:43 -0300 | [diff] [blame] | 494 | } else { |
| 495 | t->sgIF = 124; |
| 496 | t->tda8290_easy_mode = 0x10; |
| 497 | mode = "xx"; |
Nickolay V. Shmyrev | 70b6934 | 2005-11-08 21:36:50 -0800 | [diff] [blame] | 498 | } |
Hartmut Hackmann | e65ec75 | 2007-03-22 20:58:43 -0300 | [diff] [blame] | 499 | tuner_dbg("setting tda8290 to system %s\n", mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 503 | { |
| 504 | struct tuner *t = i2c_get_clientdata(c); |
| 505 | |
| 506 | set_audio(t); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 507 | tda8290_tune(c, t->sgIF, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) |
| 511 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 512 | /* if frequency is 5.5 MHz */ |
| 513 | tda8290_tune(c, 88, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static int has_signal(struct i2c_client *c) |
| 517 | { |
| 518 | unsigned char i2c_get_afc[1] = { 0x1B }; |
| 519 | unsigned char afc = 0; |
| 520 | |
| 521 | i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); |
| 522 | i2c_master_recv(c, &afc, 1); |
| 523 | return (afc & 0x80)? 65535:0; |
| 524 | } |
| 525 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 526 | /*---------------------------------------------------------------------*/ |
| 527 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 528 | static void standby(struct i2c_client *c) |
| 529 | { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 530 | struct tuner *t = i2c_get_clientdata(c); |
| 531 | unsigned char cb1[] = { 0x30, 0xD0 }; |
| 532 | unsigned char tda8290_standby[] = { 0x00, 0x02 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 533 | unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 534 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; |
| 535 | |
| 536 | tda8290_i2c_bridge(c, 1); |
| 537 | if (t->tda827x_ver != 0) |
| 538 | cb1[1] = 0x90; |
| 539 | i2c_transfer(c->adapter, &msg, 1); |
| 540 | tda8290_i2c_bridge(c, 0); |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 541 | i2c_master_send(c, tda8290_agc_tri, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 542 | i2c_master_send(c, tda8290_standby, 2); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 545 | |
| 546 | static void tda8290_init_if(struct i2c_client *c) |
| 547 | { |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 548 | struct tuner *t = i2c_get_clientdata(c); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 549 | unsigned char set_VS[] = { 0x30, 0x6F }; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 550 | unsigned char set_GP00_CF[] = { 0x20, 0x01 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 551 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
| 552 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 553 | if ((t->config == 1) || (t->config == 2)) |
| 554 | i2c_master_send(c, set_GP00_CF, 2); |
| 555 | else |
| 556 | i2c_master_send(c, set_GP01_CF, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 557 | i2c_master_send(c, set_VS, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static void tda8290_init_tuner(struct i2c_client *c) |
| 561 | { |
| 562 | struct tuner *t = i2c_get_clientdata(c); |
| 563 | unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 564 | 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 565 | unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 566 | 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 567 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, |
Ricardo Cerqueira | c2f6f9d | 2005-11-08 21:37:51 -0800 | [diff] [blame] | 568 | .buf=tda8275_init, .len = 14}; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 569 | if (t->tda827x_ver != 0) |
| 570 | msg.buf = tda8275a_init; |
| 571 | |
| 572 | tda8290_i2c_bridge(c, 1); |
| 573 | i2c_transfer(c->adapter, &msg, 1); |
| 574 | tda8290_i2c_bridge(c, 0); |
| 575 | } |
| 576 | |
| 577 | /*---------------------------------------------------------------------*/ |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | int tda8290_init(struct i2c_client *c) |
| 580 | { |
| 581 | struct tuner *t = i2c_get_clientdata(c); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 582 | u8 data; |
| 583 | int i, ret, tuners_found; |
| 584 | u32 tuner_addrs; |
| 585 | struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 587 | tda8290_i2c_bridge(c, 1); |
| 588 | /* probe for tuner chip */ |
| 589 | tuners_found = 0; |
| 590 | tuner_addrs = 0; |
| 591 | for (i=0x60; i<= 0x63; i++) { |
| 592 | msg.addr = i; |
| 593 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 594 | if (ret == 1) { |
| 595 | tuners_found++; |
| 596 | tuner_addrs = (tuner_addrs << 8) + i; |
| 597 | } |
| 598 | } |
| 599 | /* if there is more than one tuner, we expect the right one is |
| 600 | behind the bridge and we choose the highest address that doesn't |
| 601 | give a response now |
| 602 | */ |
| 603 | tda8290_i2c_bridge(c, 0); |
| 604 | if(tuners_found > 1) |
| 605 | for (i = 0; i < tuners_found; i++) { |
| 606 | msg.addr = tuner_addrs & 0xff; |
| 607 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 608 | if(ret == 1) |
| 609 | tuner_addrs = tuner_addrs >> 8; |
| 610 | else |
| 611 | break; |
| 612 | } |
| 613 | if (tuner_addrs == 0) { |
| 614 | tuner_addrs = 0x61; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 615 | tuner_info ("could not clearly identify tuner address, defaulting to %x\n", |
Nickolay V. Shmyrev | 01cb963 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 616 | tuner_addrs); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 617 | } else { |
| 618 | tuner_addrs = tuner_addrs & 0xff; |
| 619 | tuner_info ("setting tuner address to %x\n", tuner_addrs); |
| 620 | } |
| 621 | t->tda827x_addr = tuner_addrs; |
| 622 | msg.addr = tuner_addrs; |
| 623 | |
| 624 | tda8290_i2c_bridge(c, 1); |
| 625 | ret = i2c_transfer(c->adapter, &msg, 1); |
| 626 | if( ret != 1) |
| 627 | tuner_warn ("TDA827x access failed!\n"); |
| 628 | if ((data & 0x3c) == 0) { |
| 629 | strlcpy(c->name, "tda8290+75", sizeof(c->name)); |
| 630 | t->tda827x_ver = 0; |
| 631 | } else { |
| 632 | strlcpy(c->name, "tda8290+75a", sizeof(c->name)); |
| 633 | t->tda827x_ver = 2; |
| 634 | } |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 635 | tuner_info("type set to %s\n", c->name); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 636 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 637 | t->set_tv_freq = set_tv_freq; |
| 638 | t->set_radio_freq = set_radio_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | t->has_signal = has_signal; |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 640 | t->standby = standby; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 641 | t->tda827x_lpsel = 0; |
Hartmut Hackmann | e65ec75 | 2007-03-22 20:58:43 -0300 | [diff] [blame] | 642 | t->mode = V4L2_TUNER_ANALOG_TV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 644 | tda8290_init_tuner(c); |
| 645 | tda8290_init_if(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 649 | int tda8290_probe(struct i2c_client *c) |
| 650 | { |
Hartmut Hackmann | 44fd06f | 2006-02-27 00:09:11 -0300 | [diff] [blame] | 651 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 652 | unsigned char easy_mode_b[] = { 0x01, 0x02 }; |
| 653 | unsigned char easy_mode_g[] = { 0x01, 0x04 }; |
| 654 | unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 }; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 655 | unsigned char addr_dto_lsb = 0x07; |
| 656 | unsigned char data; |
| 657 | |
| 658 | i2c_master_send(c, easy_mode_b, 2); |
| 659 | i2c_master_send(c, soft_reset, 2); |
| 660 | i2c_master_send(c, &addr_dto_lsb, 1); |
| 661 | i2c_master_recv(c, &data, 1); |
| 662 | if (data == 0) { |
| 663 | i2c_master_send(c, easy_mode_g, 2); |
| 664 | i2c_master_send(c, soft_reset, 2); |
| 665 | i2c_master_send(c, &addr_dto_lsb, 1); |
| 666 | i2c_master_recv(c, &data, 1); |
| 667 | if (data == 0x7b) { |
| 668 | return 0; |
| 669 | } |
| 670 | } |
Hartmut Hackmann | 44fd06f | 2006-02-27 00:09:11 -0300 | [diff] [blame] | 671 | i2c_master_send(c, restore_9886, 3); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 672 | return -1; |
| 673 | } |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* |
| 676 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 677 | * --------------------------------------------------------------------------- |
| 678 | * Local variables: |
| 679 | * c-basic-offset: 8 |
| 680 | * End: |
| 681 | */ |