blob: ed22be0f59418c0d82b581d1e584a394b99abee4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -08002
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.
Michael Krufky910bb3e2007-08-27 21:22:20 -030019
20 This "tda8290" module was split apart from the original "tuner" module.
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080021*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/delay.h>
Michael Krufkyffbb8072007-08-21 01:14:12 -030025#include <linux/videodev.h>
Michael Krufky910bb3e2007-08-27 21:22:20 -030026#include "tda8290.h"
Michael Krufky746d97322007-08-25 19:08:45 -030027#include "tda827x.h"
Michael Krufky5bea1cd2007-10-22 09:56:38 -030028#include "tda18271.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030029
Michael Krufky5bea1cd2007-10-22 09:56:38 -030030static int tuner_debug;
Michael Krufky746d97322007-08-25 19:08:45 -030031module_param_named(debug, tuner_debug, int, 0644);
Michael Krufky910bb3e2007-08-27 21:22:20 -030032MODULE_PARM_DESC(debug, "enable verbose debug messages");
33
34#define PREFIX "tda8290 "
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/* ---------------------------------------------------------------------- */
37
Michael Krufkyb2083192007-05-29 22:54:06 -030038struct tda8290_priv {
Michael Krufkydb8a6952007-08-21 01:24:42 -030039 struct tuner_i2c_props i2c_props;
40
Michael Krufkyb2083192007-05-29 22:54:06 -030041 unsigned char tda8290_easy_mode;
Michael Krufky746d97322007-08-25 19:08:45 -030042
Michael Krufkyb2083192007-05-29 22:54:06 -030043 unsigned char tda827x_addr;
Michael Krufky8c125f2c2007-10-27 02:00:57 -030044
45 unsigned char ver;
46#define TDA8290 1
47#define TDA8295 2
48#define TDA8275 4
49#define TDA8275A 8
50#define TDA18271 16
Michael Krufky910bb3e2007-08-27 21:22:20 -030051
Michael Krufky746d97322007-08-25 19:08:45 -030052 struct tda827x_config cfg;
Michael Krufky4e9154b2007-10-21 19:39:50 -030053
54 struct tuner *t;
Michael Krufkyb2083192007-05-29 22:54:06 -030055};
56
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080057/*---------------------------------------------------------------------*/
58
Michael Krufkya72dd302007-10-24 09:30:17 -030059static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080060{
Michael Krufky4e9154b2007-10-21 19:39:50 -030061 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -030062
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080063 unsigned char enable[2] = { 0x21, 0xC0 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -020064 unsigned char disable[2] = { 0x21, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080065 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030066
67 if (close) {
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080068 msg = enable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030069 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080070 /* let the bridge stabilize */
71 msleep(20);
72 } else {
73 msg = disable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030074 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080075 }
Michael Krufkya72dd302007-10-24 09:30:17 -030076
77 return 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080078}
79
Michael Krufkya72dd302007-10-24 09:30:17 -030080static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
Michael Krufky5bea1cd2007-10-22 09:56:38 -030081{
Michael Krufky4e9154b2007-10-21 19:39:50 -030082 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -030083
84 unsigned char enable[2] = { 0x45, 0xc1 };
85 unsigned char disable[2] = { 0x46, 0x00 };
86 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
87 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030088
Michael Krufky5bea1cd2007-10-22 09:56:38 -030089 if (close) {
90 msg = enable;
91 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
92 /* let the bridge stabilize */
93 msleep(20);
94 } else {
95 msg = disable;
96 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
97 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
98
99 buf[2] = msg[1];
100 buf[2] &= ~0x04;
101 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
102 msleep(5);
103
104 msg[1] |= 0x04;
105 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
106 }
Michael Krufkya72dd302007-10-24 09:30:17 -0300107
108 return 0;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300109}
110
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800111/*---------------------------------------------------------------------*/
112
Michael Krufky4e9154b2007-10-21 19:39:50 -0300113static void set_audio(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800114{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300115 struct tda8290_priv *priv = fe->analog_demod_priv;
116 struct tuner *t = priv->t;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300117 char* mode;
118
Michael Krufky746d97322007-08-25 19:08:45 -0300119 if (t->std & V4L2_STD_MN) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300120 priv->tda8290_easy_mode = 0x01;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300121 mode = "MN";
Michael Krufky746d97322007-08-25 19:08:45 -0300122 } else if (t->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300123 priv->tda8290_easy_mode = 0x02;
124 mode = "B";
Michael Krufky746d97322007-08-25 19:08:45 -0300125 } else if (t->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300126 priv->tda8290_easy_mode = 0x04;
127 mode = "GH";
Michael Krufky746d97322007-08-25 19:08:45 -0300128 } else if (t->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300129 priv->tda8290_easy_mode = 0x08;
130 mode = "I";
Michael Krufky746d97322007-08-25 19:08:45 -0300131 } else if (t->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300132 priv->tda8290_easy_mode = 0x10;
133 mode = "DK";
Michael Krufky746d97322007-08-25 19:08:45 -0300134 } else if (t->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300135 priv->tda8290_easy_mode = 0x20;
136 mode = "L";
Michael Krufky746d97322007-08-25 19:08:45 -0300137 } else if (t->std & V4L2_STD_SECAM_LC) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300138 priv->tda8290_easy_mode = 0x40;
139 mode = "LC";
140 } else {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300141 priv->tda8290_easy_mode = 0x10;
142 mode = "xx";
143 }
144
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300145 tuner_dbg("setting tda829x to system %s\n", mode);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300146}
147
Michael Krufky4e9154b2007-10-21 19:39:50 -0300148static void tda8290_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300149{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300150 struct tda8290_priv *priv = fe->analog_demod_priv;
151 struct tuner *t = priv->t;
152
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800153 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300154 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800155 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200156 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800157 unsigned char gainset_off[] = { 0x28, 0x14 };
158 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
159 unsigned char adc_head_6[] = { 0x05, 0x04 };
160 unsigned char adc_head_9[] = { 0x05, 0x02 };
161 unsigned char adc_head_12[] = { 0x05, 0x01 };
162 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
163 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
164 unsigned char gainset_2[] = { 0x28, 0x64 };
165 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
166 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
167 unsigned char if_agc_set[] = { 0x0f, 0x81 };
168 unsigned char addr_adc_sat = 0x1a;
169 unsigned char addr_agc_stat = 0x1d;
170 unsigned char addr_pll_stat = 0x1b;
171 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800172 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300173 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800174
Michael Krufky746d97322007-08-25 19:08:45 -0300175 struct analog_parameters params = {
176 .frequency = freq,
177 .mode = t->mode,
178 .audmode = t->audmode,
179 .std = t->std
180 };
Michael Krufky910bb3e2007-08-27 21:22:20 -0300181
Michael Krufky4e9154b2007-10-21 19:39:50 -0300182 set_audio(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300183
184 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300185 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
186 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
187 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800188 msleep(1);
189
Michael Krufkyb2083192007-05-29 22:54:06 -0300190 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300191 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
192 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
193 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300194 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300195 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800196 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300197 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
198 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800199
Michael Krufky4e9154b2007-10-21 19:39:50 -0300200 tda8290_i2c_bridge(fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300201
Michael Krufky4e9154b2007-10-21 19:39:50 -0300202 if (fe->ops.tuner_ops.set_analog_params)
203 fe->ops.tuner_ops.set_analog_params(fe, &params);
Michael Krufky746d97322007-08-25 19:08:45 -0300204
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300205 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300206 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
207 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300208 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300209 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
210 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
211 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
212 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300213 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
214 break;
215 } else {
216 tuner_dbg("tda8290 not locked, no signal?\n");
217 msleep(100);
218 }
219 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800220 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800221 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
222 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
223 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300224 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800225 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300226 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
227 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
228 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
229 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800230 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800231 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
232 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300233 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300234 priv->cfg.agcf(fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800235 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300236 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
237 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
238 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
239 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800240 if((agc_stat > 115) || !(pll_stat & 0x80)) {
241 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300242 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
243 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800244 msleep(100);
245 }
246 }
247 }
248
249 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300250 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300251 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
252 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
253 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
254 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800255 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800256 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300257 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800258 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300259 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800260 }
261 }
262
Michael Krufky4e9154b2007-10-21 19:39:50 -0300263 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300264 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800265}
266
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800267/*---------------------------------------------------------------------*/
268
Michael Krufky4e9154b2007-10-21 19:39:50 -0300269static void tda8295_power(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300270{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300271 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300272 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
273
274 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
275 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
276
277 if (enable)
278 buf[1] = 0x01;
279 else
280 buf[1] = 0x03;
281
282 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
283}
284
Michael Krufky4e9154b2007-10-21 19:39:50 -0300285static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300286{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300287 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300288 unsigned char buf[] = { 0x01, 0x00 };
289
290 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
291 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
292
293 if (enable)
294 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
295 else
296 buf[1] = 0x00; /* reset active bit */
297
298 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
299}
300
Michael Krufky4e9154b2007-10-21 19:39:50 -0300301static void tda8295_set_video_std(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300302{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300303 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300304 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
305
306 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
307
Michael Krufky4e9154b2007-10-21 19:39:50 -0300308 tda8295_set_easy_mode(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300309 msleep(20);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300310 tda8295_set_easy_mode(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300311}
312
313/*---------------------------------------------------------------------*/
314
Michael Krufky4e9154b2007-10-21 19:39:50 -0300315static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300316{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300317 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300318 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
319
320 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
321 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
322
323 if (enable)
324 buf[1] &= ~0x40;
325 else
326 buf[1] |= 0x40;
327
328 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
329}
330
Michael Krufky4e9154b2007-10-21 19:39:50 -0300331static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300332{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300333 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300334 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
335 unsigned char set_gpio_val[] = { 0x46, 0x00 };
336
337 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
338 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
339 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
340 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
341
342 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
343
344 if (enable) {
345 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
346 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
347 }
348 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
349 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
350}
351
Michael Krufky4e9154b2007-10-21 19:39:50 -0300352static int tda8295_has_signal(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300353{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300354 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300355
356 unsigned char hvpll_stat = 0x26;
357 unsigned char ret;
358
359 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
360 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
361 return (ret & 0x01) ? 65535 : 0;
362}
363
364/*---------------------------------------------------------------------*/
365
Michael Krufky4e9154b2007-10-21 19:39:50 -0300366static void tda8295_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300367{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300368 struct tda8290_priv *priv = fe->analog_demod_priv;
369 struct tuner *t = priv->t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300370
371 unsigned char blanking_mode[] = { 0x1d, 0x00 };
372
373 struct analog_parameters params = {
374 .frequency = freq,
375 .mode = t->mode,
376 .audmode = t->audmode,
377 .std = t->std
378 };
379
Michael Krufky4e9154b2007-10-21 19:39:50 -0300380 set_audio(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300381
Michael Krufky5c82f442007-10-22 01:10:39 -0300382 tuner_dbg("%s: freq = %d\n", __FUNCTION__, freq);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300383
Michael Krufky4e9154b2007-10-21 19:39:50 -0300384 tda8295_power(fe, 1);
385 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300386
387 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
388 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
389
Michael Krufky4e9154b2007-10-21 19:39:50 -0300390 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300391
392 blanking_mode[1] = 0x03;
393 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
394 msleep(20);
395
Michael Krufky4e9154b2007-10-21 19:39:50 -0300396 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300397
Michael Krufky4e9154b2007-10-21 19:39:50 -0300398 if (fe->ops.tuner_ops.set_analog_params)
399 fe->ops.tuner_ops.set_analog_params(fe, &params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300400
401 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300402 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300403
Michael Krufky4e9154b2007-10-21 19:39:50 -0300404 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300405 tuner_dbg("tda8295 is locked\n");
406 else
407 tuner_dbg("tda8295 not locked, no signal?\n");
408
Michael Krufky4e9154b2007-10-21 19:39:50 -0300409 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300410}
411
412/*---------------------------------------------------------------------*/
413
Michael Krufky4e9154b2007-10-21 19:39:50 -0300414static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300416 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 unsigned char i2c_get_afc[1] = { 0x1B };
419 unsigned char afc = 0;
420
Michael Krufkydb8a6952007-08-21 01:24:42 -0300421 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
422 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300423 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300424}
425
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800426/*---------------------------------------------------------------------*/
427
Michael Krufky4e9154b2007-10-21 19:39:50 -0300428static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700429{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300430 struct tda8290_priv *priv = fe->analog_demod_priv;
431
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800432 unsigned char cb1[] = { 0x30, 0xD0 };
433 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200434 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300435 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800436
Michael Krufky4e9154b2007-10-21 19:39:50 -0300437 tda8290_i2c_bridge(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300438 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800439 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300440 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300441 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300442 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
443 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700444}
445
Michael Krufky4e9154b2007-10-21 19:39:50 -0300446static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300447{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300448 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300449
Michael Krufky4e9154b2007-10-21 19:39:50 -0300450 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300451}
452
Michael Krufky4e9154b2007-10-21 19:39:50 -0300453static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800454{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300455 struct tda8290_priv *priv = fe->analog_demod_priv;
456 struct tuner *t = priv->t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300457
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800458 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300459 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800460 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
461
Michael Krufky746d97322007-08-25 19:08:45 -0300462 if ((t->config == 1) || (t->config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300463 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300464 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300465 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
466 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800467}
468
Michael Krufky4e9154b2007-10-21 19:39:50 -0300469static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300470{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300471 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300472
473 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
474 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
475 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
476 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
477 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
478 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
479 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
480
Michael Krufky4e9154b2007-10-21 19:39:50 -0300481 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300482
Michael Krufky4e9154b2007-10-21 19:39:50 -0300483 tda8295_set_easy_mode(fe, 0);
484 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300485
486 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
487 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
488 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
489 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
490 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
491 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
492 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
493
Michael Krufky4e9154b2007-10-21 19:39:50 -0300494 tda8295_agc1_out(fe, 0);
495 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300496}
497
Michael Krufky4e9154b2007-10-21 19:39:50 -0300498static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800499{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300500 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800501 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800502 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800503 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800504 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300505 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800506 .buf=tda8275_init, .len = 14};
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300507 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800508 msg.buf = tda8275a_init;
509
Michael Krufky4e9154b2007-10-21 19:39:50 -0300510 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300511 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300512 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800513}
514
515/*---------------------------------------------------------------------*/
516
Michael Krufky4e9154b2007-10-21 19:39:50 -0300517static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300518{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300519 if (fe->ops.tuner_ops.release)
520 fe->ops.tuner_ops.release(fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300521
Michael Krufky4e9154b2007-10-21 19:39:50 -0300522 kfree(fe->analog_demod_priv);
523 fe->analog_demod_priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300524}
525
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300526static int tda829x_find_tuner(struct dvb_frontend *fe)
527{
528 struct tda8290_priv *priv = fe->analog_demod_priv;
529 struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
530 struct tuner *t = priv->t;
531 int i, ret, tuners_found;
532 u32 tuner_addrs;
533 u8 data;
534 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
535
536 if (NULL == ops)
537 return -EINVAL;
538
539 ops->i2c_gate_ctrl(fe, 1);
540
541 /* probe for tuner chip */
542 tuners_found = 0;
543 tuner_addrs = 0;
544 for (i = 0x60; i <= 0x63; i++) {
545 msg.addr = i;
546 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
547 if (ret == 1) {
548 tuners_found++;
549 tuner_addrs = (tuner_addrs << 8) + i;
550 }
551 }
552 /* if there is more than one tuner, we expect the right one is
553 behind the bridge and we choose the highest address that doesn't
554 give a response now
555 */
556
557 ops->i2c_gate_ctrl(fe, 0);
558
559 if (tuners_found > 1)
560 for (i = 0; i < tuners_found; i++) {
561 msg.addr = tuner_addrs & 0xff;
562 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
563 if (ret == 1)
564 tuner_addrs = tuner_addrs >> 8;
565 else
566 break;
567 }
568
569 if (tuner_addrs == 0) {
570 tuner_addrs = 0x60;
571 tuner_info("could not clearly identify tuner address, "
572 "defaulting to %x\n", tuner_addrs);
573 } else {
574 tuner_addrs = tuner_addrs & 0xff;
575 tuner_info("setting tuner address to %x\n", tuner_addrs);
576 }
577 priv->tda827x_addr = tuner_addrs;
578 msg.addr = tuner_addrs;
579
580 ops->i2c_gate_ctrl(fe, 1);
581 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
582
583 if (ret != 1) {
584 tuner_warn("tuner access failed!\n");
585 return -EREMOTEIO;
586 }
587
588 if (data == 0x83) {
589 priv->ver |= TDA18271;
590 tda18271_attach(&t->fe, priv->tda827x_addr,
591 priv->i2c_props.adap);
592 } else {
593 if ((data & 0x3c) == 0)
594 priv->ver |= TDA8275;
595 else
596 priv->ver |= TDA8275A;
597
598 tda827x_attach(&t->fe, priv->tda827x_addr,
599 priv->i2c_props.adap, &priv->cfg);
600
601 /* FIXME: tda827x module doesn't probe the tuner until
602 * tda827x_initial_sleep is called
603 */
604 if (t->fe.ops.tuner_ops.sleep)
605 t->fe.ops.tuner_ops.sleep(&t->fe);
606 }
607 ops->i2c_gate_ctrl(fe, 0);
608
609 switch (priv->ver) {
610 case TDA8290 | TDA8275:
611 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
612 break;
613 case TDA8295 | TDA8275:
614 strlcpy(t->i2c.name, "tda8295+75", sizeof(t->i2c.name));
615 break;
616 case TDA8290 | TDA8275A:
617 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
618 break;
619 case TDA8295 | TDA8275A:
620 strlcpy(t->i2c.name, "tda8295+75a", sizeof(t->i2c.name));
621 break;
622 case TDA8290 | TDA18271:
623 strlcpy(t->i2c.name, "tda8290+18271", sizeof(t->i2c.name));
624 break;
625 case TDA8295 | TDA18271:
626 strlcpy(t->i2c.name, "tda8295+18271", sizeof(t->i2c.name));
627 break;
628 default:
629 return -EINVAL;
630 }
631
632 return 0;
633}
634
Michael Krufky1dde7a42007-10-21 13:40:56 -0300635static struct analog_tuner_ops tda8290_tuner_ops = {
Michael Krufky746d97322007-08-25 19:08:45 -0300636 .set_tv_freq = tda8290_set_freq,
637 .set_radio_freq = tda8290_set_freq,
638 .has_signal = tda8290_has_signal,
639 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300640 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300641 .i2c_gate_ctrl = tda8290_i2c_bridge,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300642};
643
Michael Krufky1dde7a42007-10-21 13:40:56 -0300644static struct analog_tuner_ops tda8295_tuner_ops = {
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300645 .set_tv_freq = tda8295_set_freq,
646 .set_radio_freq = tda8295_set_freq,
647 .has_signal = tda8295_has_signal,
648 .standby = tda8295_standby,
649 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300650 .i2c_gate_ctrl = tda8295_i2c_bridge,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300651};
652
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300653int tda829x_attach(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300655 struct dvb_frontend *fe = &t->fe;
Michael Krufkyb2083192007-05-29 22:54:06 -0300656 struct tda8290_priv *priv = NULL;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300657
658 unsigned char tda8290_id[] = { 0x1f, 0x00 };
659#define TDA8290_ID 0x89
660 unsigned char tda8295_id[] = { 0x2f, 0x00 };
661#define TDA8295_ID 0x8a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Michael Krufkyb2083192007-05-29 22:54:06 -0300663 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
664 if (priv == NULL)
Michael Krufky746d97322007-08-25 19:08:45 -0300665 return -ENOMEM;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300666 fe->analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300667
Michael Krufky746d97322007-08-25 19:08:45 -0300668 priv->i2c_props.addr = t->i2c.addr;
669 priv->i2c_props.adap = t->i2c.adapter;
670 priv->cfg.config = &t->config;
671 priv->cfg.tuner_callback = t->tuner_callback;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300672 priv->t = t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300673
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300674 /* detect tda8290 */
675 tuner_i2c_xfer_send(&priv->i2c_props, &tda8290_id[0], 1);
676 tuner_i2c_xfer_recv(&priv->i2c_props, &tda8290_id[1], 1);
677 if (tda8290_id[1] == TDA8290_ID) {
678 priv->ver = TDA8290;
679 fe->ops.analog_demod_ops = &tda8290_tuner_ops;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800680 }
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300681
682 /* detect tda8295 */
683 tuner_i2c_xfer_send(&priv->i2c_props, &tda8295_id[0], 1);
684 tuner_i2c_xfer_recv(&priv->i2c_props, &tda8295_id[1], 1);
685 if (tda8295_id[1] == TDA8295_ID) {
686 priv->ver = TDA8295;
687 fe->ops.analog_demod_ops = &tda8295_tuner_ops;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800688 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800689
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300690 if (tda829x_find_tuner(fe) < 0)
691 return -EINVAL;
Michael Krufky746d97322007-08-25 19:08:45 -0300692
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300693 if (priv->ver & TDA8290) {
694 tda8290_init_tuner(fe);
695 tda8290_init_if(fe);
696 } else if (priv->ver & TDA8295)
697 tda8295_init_if(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300698
699 tuner_info("type set to %s\n", t->i2c.name);
700
Michael Krufky746d97322007-08-25 19:08:45 -0300701 t->mode = V4L2_TUNER_ANALOG_TV;
702
Michael Krufky746d97322007-08-25 19:08:45 -0300703 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300705EXPORT_SYMBOL_GPL(tda829x_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Michael Krufky746d97322007-08-25 19:08:45 -0300707int tda8290_probe(struct tuner *t)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800708{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300709 struct tuner_i2c_props i2c_props = {
Michael Krufky746d97322007-08-25 19:08:45 -0300710 .adap = t->i2c.adapter,
711 .addr = t->i2c.addr
Michael Krufky910bb3e2007-08-27 21:22:20 -0300712 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300713
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300714 unsigned char soft_reset[] = { 0x00, 0x00 };
715 unsigned char easy_mode_b[] = { 0x01, 0x02 };
716 unsigned char easy_mode_g[] = { 0x01, 0x04 };
717 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800718 unsigned char addr_dto_lsb = 0x07;
719 unsigned char data;
720
Michael Krufky910bb3e2007-08-27 21:22:20 -0300721 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
722 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
723 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
724 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800725 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300726 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
727 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
728 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
729 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800730 if (data == 0x7b) {
731 return 0;
732 }
733 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300734 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800735 return -1;
736}
Michael Krufky910bb3e2007-08-27 21:22:20 -0300737EXPORT_SYMBOL_GPL(tda8290_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300738
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300739MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300740MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300741MODULE_LICENSE("GPL");
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743/*
744 * Overrides for Emacs so that we follow Linus's tabbing style.
745 * ---------------------------------------------------------------------------
746 * Local variables:
747 * c-basic-offset: 8
748 * End:
749 */