blob: 1b19b93eabec92f7ca3436fd4fa48829b6ef0ae7 [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;
44 unsigned char tda827x_ver;
Michael Krufky910bb3e2007-08-27 21:22:20 -030045
Michael Krufky746d97322007-08-25 19:08:45 -030046 struct tda827x_config cfg;
Michael Krufky4e9154b2007-10-21 19:39:50 -030047
48 struct tuner *t;
Michael Krufkyb2083192007-05-29 22:54:06 -030049};
50
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080051/*---------------------------------------------------------------------*/
52
Michael Krufky4e9154b2007-10-21 19:39:50 -030053static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080054{
Michael Krufky4e9154b2007-10-21 19:39:50 -030055 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -030056
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080057 unsigned char enable[2] = { 0x21, 0xC0 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -020058 unsigned char disable[2] = { 0x21, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080059 unsigned char *msg;
60 if(close) {
61 msg = enable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030062 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080063 /* let the bridge stabilize */
64 msleep(20);
65 } else {
66 msg = disable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030067 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080068 }
69}
70
Michael Krufky4e9154b2007-10-21 19:39:50 -030071static void tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
Michael Krufky5bea1cd2007-10-22 09:56:38 -030072{
Michael Krufky4e9154b2007-10-21 19:39:50 -030073 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -030074
75 unsigned char enable[2] = { 0x45, 0xc1 };
76 unsigned char disable[2] = { 0x46, 0x00 };
77 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
78 unsigned char *msg;
79 if (close) {
80 msg = enable;
81 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
82 /* let the bridge stabilize */
83 msleep(20);
84 } else {
85 msg = disable;
86 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
87 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
88
89 buf[2] = msg[1];
90 buf[2] &= ~0x04;
91 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
92 msleep(5);
93
94 msg[1] |= 0x04;
95 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
96 }
97}
98
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080099/*---------------------------------------------------------------------*/
100
Michael Krufky4e9154b2007-10-21 19:39:50 -0300101static void set_audio(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800102{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300103 struct tda8290_priv *priv = fe->analog_demod_priv;
104 struct tuner *t = priv->t;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300105 char* mode;
106
Michael Krufky746d97322007-08-25 19:08:45 -0300107 if (t->std & V4L2_STD_MN) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300108 priv->tda8290_easy_mode = 0x01;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300109 mode = "MN";
Michael Krufky746d97322007-08-25 19:08:45 -0300110 } else if (t->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300111 priv->tda8290_easy_mode = 0x02;
112 mode = "B";
Michael Krufky746d97322007-08-25 19:08:45 -0300113 } else if (t->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300114 priv->tda8290_easy_mode = 0x04;
115 mode = "GH";
Michael Krufky746d97322007-08-25 19:08:45 -0300116 } else if (t->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300117 priv->tda8290_easy_mode = 0x08;
118 mode = "I";
Michael Krufky746d97322007-08-25 19:08:45 -0300119 } else if (t->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300120 priv->tda8290_easy_mode = 0x10;
121 mode = "DK";
Michael Krufky746d97322007-08-25 19:08:45 -0300122 } else if (t->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300123 priv->tda8290_easy_mode = 0x20;
124 mode = "L";
Michael Krufky746d97322007-08-25 19:08:45 -0300125 } else if (t->std & V4L2_STD_SECAM_LC) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300126 priv->tda8290_easy_mode = 0x40;
127 mode = "LC";
128 } else {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300129 priv->tda8290_easy_mode = 0x10;
130 mode = "xx";
131 }
132
Michael Krufky910bb3e2007-08-27 21:22:20 -0300133 tuner_dbg("setting tda8290 to system %s\n", mode);
134}
135
Michael Krufky4e9154b2007-10-21 19:39:50 -0300136static void tda8290_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300137{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300138 struct tda8290_priv *priv = fe->analog_demod_priv;
139 struct tuner *t = priv->t;
140
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800141 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300142 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800143 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200144 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800145 unsigned char gainset_off[] = { 0x28, 0x14 };
146 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
147 unsigned char adc_head_6[] = { 0x05, 0x04 };
148 unsigned char adc_head_9[] = { 0x05, 0x02 };
149 unsigned char adc_head_12[] = { 0x05, 0x01 };
150 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
151 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
152 unsigned char gainset_2[] = { 0x28, 0x64 };
153 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
154 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
155 unsigned char if_agc_set[] = { 0x0f, 0x81 };
156 unsigned char addr_adc_sat = 0x1a;
157 unsigned char addr_agc_stat = 0x1d;
158 unsigned char addr_pll_stat = 0x1b;
159 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800160 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300161 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800162
Michael Krufky746d97322007-08-25 19:08:45 -0300163 struct analog_parameters params = {
164 .frequency = freq,
165 .mode = t->mode,
166 .audmode = t->audmode,
167 .std = t->std
168 };
Michael Krufky910bb3e2007-08-27 21:22:20 -0300169
Michael Krufky4e9154b2007-10-21 19:39:50 -0300170 set_audio(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300171
172 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300173 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
174 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
175 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800176 msleep(1);
177
Michael Krufkyb2083192007-05-29 22:54:06 -0300178 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300179 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
180 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
181 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300182 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300183 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800184 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300185 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
186 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800187
Michael Krufky4e9154b2007-10-21 19:39:50 -0300188 tda8290_i2c_bridge(fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300189
Michael Krufky4e9154b2007-10-21 19:39:50 -0300190 if (fe->ops.tuner_ops.set_analog_params)
191 fe->ops.tuner_ops.set_analog_params(fe, &params);
Michael Krufky746d97322007-08-25 19:08:45 -0300192
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300193 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300194 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
195 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300196 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300197 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
198 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
199 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
200 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300201 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
202 break;
203 } else {
204 tuner_dbg("tda8290 not locked, no signal?\n");
205 msleep(100);
206 }
207 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800208 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800209 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
210 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
211 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300212 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800213 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300214 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
215 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
216 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
217 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800218 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800219 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
220 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300221 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300222 priv->cfg.agcf(fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800223 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300224 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
225 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
226 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
227 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800228 if((agc_stat > 115) || !(pll_stat & 0x80)) {
229 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300230 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
231 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800232 msleep(100);
233 }
234 }
235 }
236
237 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300238 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300239 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
240 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
241 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
242 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800243 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800244 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300245 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800246 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300247 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800248 }
249 }
250
Michael Krufky4e9154b2007-10-21 19:39:50 -0300251 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300252 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800253}
254
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800255/*---------------------------------------------------------------------*/
256
Michael Krufky4e9154b2007-10-21 19:39:50 -0300257static void tda8295_power(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300258{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300259 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300260 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
261
262 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
263 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
264
265 if (enable)
266 buf[1] = 0x01;
267 else
268 buf[1] = 0x03;
269
270 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
271}
272
Michael Krufky4e9154b2007-10-21 19:39:50 -0300273static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300274{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300275 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300276 unsigned char buf[] = { 0x01, 0x00 };
277
278 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
279 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
280
281 if (enable)
282 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
283 else
284 buf[1] = 0x00; /* reset active bit */
285
286 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
287}
288
Michael Krufky4e9154b2007-10-21 19:39:50 -0300289static void tda8295_set_video_std(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300290{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300291 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300292 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
293
294 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
295
Michael Krufky4e9154b2007-10-21 19:39:50 -0300296 tda8295_set_easy_mode(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300297 msleep(20);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300298 tda8295_set_easy_mode(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300299}
300
301/*---------------------------------------------------------------------*/
302
Michael Krufky4e9154b2007-10-21 19:39:50 -0300303static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300304{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300305 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300306 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
307
308 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
309 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
310
311 if (enable)
312 buf[1] &= ~0x40;
313 else
314 buf[1] |= 0x40;
315
316 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
317}
318
Michael Krufky4e9154b2007-10-21 19:39:50 -0300319static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300320{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300321 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300322 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
323 unsigned char set_gpio_val[] = { 0x46, 0x00 };
324
325 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
326 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
327 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
328 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
329
330 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
331
332 if (enable) {
333 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
334 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
335 }
336 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
337 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
338}
339
Michael Krufky4e9154b2007-10-21 19:39:50 -0300340static int tda8295_has_signal(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300341{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300342 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300343
344 unsigned char hvpll_stat = 0x26;
345 unsigned char ret;
346
347 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
348 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
349 return (ret & 0x01) ? 65535 : 0;
350}
351
352/*---------------------------------------------------------------------*/
353
Michael Krufky4e9154b2007-10-21 19:39:50 -0300354static void tda8295_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300355{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300356 struct tda8290_priv *priv = fe->analog_demod_priv;
357 struct tuner *t = priv->t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300358
359 unsigned char blanking_mode[] = { 0x1d, 0x00 };
360
361 struct analog_parameters params = {
362 .frequency = freq,
363 .mode = t->mode,
364 .audmode = t->audmode,
365 .std = t->std
366 };
367
Michael Krufky4e9154b2007-10-21 19:39:50 -0300368 set_audio(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300369
Michael Krufky5c82f442007-10-22 01:10:39 -0300370 tuner_dbg("%s: freq = %d\n", __FUNCTION__, freq);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300371
Michael Krufky4e9154b2007-10-21 19:39:50 -0300372 tda8295_power(fe, 1);
373 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300374
375 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
376 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
377
Michael Krufky4e9154b2007-10-21 19:39:50 -0300378 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300379
380 blanking_mode[1] = 0x03;
381 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
382 msleep(20);
383
Michael Krufky4e9154b2007-10-21 19:39:50 -0300384 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300385
Michael Krufky4e9154b2007-10-21 19:39:50 -0300386 if (fe->ops.tuner_ops.set_analog_params)
387 fe->ops.tuner_ops.set_analog_params(fe, &params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300388
389 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300390 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300391
Michael Krufky4e9154b2007-10-21 19:39:50 -0300392 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300393 tuner_dbg("tda8295 is locked\n");
394 else
395 tuner_dbg("tda8295 not locked, no signal?\n");
396
Michael Krufky4e9154b2007-10-21 19:39:50 -0300397 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300398}
399
400/*---------------------------------------------------------------------*/
401
Michael Krufky4e9154b2007-10-21 19:39:50 -0300402static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300404 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 unsigned char i2c_get_afc[1] = { 0x1B };
407 unsigned char afc = 0;
408
Michael Krufkydb8a6952007-08-21 01:24:42 -0300409 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
410 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300411 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300412}
413
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800414/*---------------------------------------------------------------------*/
415
Michael Krufky4e9154b2007-10-21 19:39:50 -0300416static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700417{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300418 struct tda8290_priv *priv = fe->analog_demod_priv;
419
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800420 unsigned char cb1[] = { 0x30, 0xD0 };
421 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200422 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300423 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800424
Michael Krufky4e9154b2007-10-21 19:39:50 -0300425 tda8290_i2c_bridge(fe, 1);
Michael Krufkyb2083192007-05-29 22:54:06 -0300426 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800427 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300428 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300429 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300430 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
431 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700432}
433
Michael Krufky4e9154b2007-10-21 19:39:50 -0300434static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300435{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300436 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300437
Michael Krufky4e9154b2007-10-21 19:39:50 -0300438 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300439}
440
Michael Krufky4e9154b2007-10-21 19:39:50 -0300441static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800442{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300443 struct tda8290_priv *priv = fe->analog_demod_priv;
444 struct tuner *t = priv->t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300445
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800446 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300447 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800448 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
449
Michael Krufky746d97322007-08-25 19:08:45 -0300450 if ((t->config == 1) || (t->config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300451 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300452 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300453 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
454 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800455}
456
Michael Krufky4e9154b2007-10-21 19:39:50 -0300457static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300458{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300459 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300460
461 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
462 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
463 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
464 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
465 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
466 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
467 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
468
Michael Krufky4e9154b2007-10-21 19:39:50 -0300469 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300470
Michael Krufky4e9154b2007-10-21 19:39:50 -0300471 tda8295_set_easy_mode(fe, 0);
472 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300473
474 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
476 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
477 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
478 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
479 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
480 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
481
Michael Krufky4e9154b2007-10-21 19:39:50 -0300482 tda8295_agc1_out(fe, 0);
483 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300484}
485
Michael Krufky4e9154b2007-10-21 19:39:50 -0300486static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800487{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300488 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800489 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800490 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800491 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800492 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300493 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800494 .buf=tda8275_init, .len = 14};
Michael Krufkyb2083192007-05-29 22:54:06 -0300495 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800496 msg.buf = tda8275a_init;
497
Michael Krufky4e9154b2007-10-21 19:39:50 -0300498 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300499 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300500 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800501}
502
503/*---------------------------------------------------------------------*/
504
Michael Krufky4e9154b2007-10-21 19:39:50 -0300505static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300506{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300507 if (fe->ops.tuner_ops.release)
508 fe->ops.tuner_ops.release(fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300509
Michael Krufky4e9154b2007-10-21 19:39:50 -0300510 kfree(fe->analog_demod_priv);
511 fe->analog_demod_priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300512}
513
Michael Krufky1dde7a42007-10-21 13:40:56 -0300514static struct analog_tuner_ops tda8290_tuner_ops = {
Michael Krufky746d97322007-08-25 19:08:45 -0300515 .set_tv_freq = tda8290_set_freq,
516 .set_radio_freq = tda8290_set_freq,
517 .has_signal = tda8290_has_signal,
518 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300519 .release = tda829x_release,
520};
521
Michael Krufky1dde7a42007-10-21 13:40:56 -0300522static struct analog_tuner_ops tda8295_tuner_ops = {
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300523 .set_tv_freq = tda8295_set_freq,
524 .set_radio_freq = tda8295_set_freq,
525 .has_signal = tda8295_has_signal,
526 .standby = tda8295_standby,
527 .release = tda829x_release,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300528};
529
Michael Krufky746d97322007-08-25 19:08:45 -0300530int tda8290_attach(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Michael Krufkyb2083192007-05-29 22:54:06 -0300532 struct tda8290_priv *priv = NULL;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800533 u8 data;
534 int i, ret, tuners_found;
535 u32 tuner_addrs;
536 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Michael Krufkyb2083192007-05-29 22:54:06 -0300538 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
539 if (priv == NULL)
Michael Krufky746d97322007-08-25 19:08:45 -0300540 return -ENOMEM;
Michael Krufky16f29162007-10-21 15:22:25 -0300541 t->fe.analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300542
Michael Krufky746d97322007-08-25 19:08:45 -0300543 priv->i2c_props.addr = t->i2c.addr;
544 priv->i2c_props.adap = t->i2c.adapter;
545 priv->cfg.config = &t->config;
546 priv->cfg.tuner_callback = t->tuner_callback;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300547 priv->t = t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300548
Michael Krufky4e9154b2007-10-21 19:39:50 -0300549 tda8290_i2c_bridge(&t->fe, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800550 /* probe for tuner chip */
551 tuners_found = 0;
552 tuner_addrs = 0;
553 for (i=0x60; i<= 0x63; i++) {
554 msg.addr = i;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300555 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800556 if (ret == 1) {
557 tuners_found++;
558 tuner_addrs = (tuner_addrs << 8) + i;
559 }
560 }
561 /* if there is more than one tuner, we expect the right one is
562 behind the bridge and we choose the highest address that doesn't
563 give a response now
564 */
Michael Krufky4e9154b2007-10-21 19:39:50 -0300565 tda8290_i2c_bridge(&t->fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800566 if(tuners_found > 1)
567 for (i = 0; i < tuners_found; i++) {
568 msg.addr = tuner_addrs & 0xff;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300569 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800570 if(ret == 1)
571 tuner_addrs = tuner_addrs >> 8;
572 else
573 break;
574 }
575 if (tuner_addrs == 0) {
576 tuner_addrs = 0x61;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300577 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
Nickolay V. Shmyrev01cb9632005-11-08 21:38:00 -0800578 tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800579 } else {
580 tuner_addrs = tuner_addrs & 0xff;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300581 tuner_info("setting tuner address to %x\n", tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800582 }
Michael Krufkyb2083192007-05-29 22:54:06 -0300583 priv->tda827x_addr = tuner_addrs;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800584 msg.addr = tuner_addrs;
585
Michael Krufky4e9154b2007-10-21 19:39:50 -0300586 tda8290_i2c_bridge(&t->fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300587
Michael Krufkydb8a6952007-08-21 01:24:42 -0300588 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800589 if( ret != 1)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300590 tuner_warn("TDA827x access failed!\n");
591
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800592 if ((data & 0x3c) == 0) {
Michael Krufky746d97322007-08-25 19:08:45 -0300593 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300594 priv->tda827x_ver = 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800595 } else {
Michael Krufky746d97322007-08-25 19:08:45 -0300596 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300597 priv->tda827x_ver = 2;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800598 }
Michael Krufky746d97322007-08-25 19:08:45 -0300599 tda827x_attach(&t->fe, priv->tda827x_addr,
600 priv->i2c_props.adap, &priv->cfg);
Michael Krufky7fd8b262007-06-06 16:15:15 -0300601
Michael Krufky746d97322007-08-25 19:08:45 -0300602 /* FIXME: tda827x module doesn't probe the tuner until
603 * tda827x_initial_sleep is called
604 */
605 if (t->fe.ops.tuner_ops.sleep)
606 t->fe.ops.tuner_ops.sleep(&t->fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Michael Krufky1dde7a42007-10-21 13:40:56 -0300608 t->fe.ops.analog_demod_ops = &tda8290_tuner_ops;
Michael Krufky746d97322007-08-25 19:08:45 -0300609
610 tuner_info("type set to %s\n", t->i2c.name);
611
Michael Krufky746d97322007-08-25 19:08:45 -0300612 t->mode = V4L2_TUNER_ANALOG_TV;
613
Michael Krufky4e9154b2007-10-21 19:39:50 -0300614 tda8290_init_tuner(&t->fe);
615 tda8290_init_if(&t->fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300616 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300618EXPORT_SYMBOL_GPL(tda8290_attach);
619
620int tda8295_attach(struct tuner *t)
621{
622 struct tda8290_priv *priv = NULL;
623 u8 data;
624 int i, ret, tuners_found;
625 u32 tuner_addrs;
626 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
627
628 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
629 if (priv == NULL)
630 return -ENOMEM;
Michael Krufky16f29162007-10-21 15:22:25 -0300631 t->fe.analog_demod_priv = priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300632
633 priv->i2c_props.addr = t->i2c.addr;
634 priv->i2c_props.adap = t->i2c.adapter;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300635 priv->t = t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300636
Michael Krufky4e9154b2007-10-21 19:39:50 -0300637 tda8295_i2c_bridge(&t->fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300638 /* probe for tuner chip */
639 tuners_found = 0;
640 tuner_addrs = 0;
641 for (i = 0x60; i <= 0x63; i++) {
642 msg.addr = i;
643 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
644 if (ret == 1) {
645 tuners_found++;
646 tuner_addrs = (tuner_addrs << 8) + i;
647 }
648 }
649 /* if there is more than one tuner, we expect the right one is
650 behind the bridge and we choose the highest address that doesn't
651 give a response now
652 */
Michael Krufky4e9154b2007-10-21 19:39:50 -0300653 tda8295_i2c_bridge(&t->fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300654 if (tuners_found > 1)
655 for (i = 0; i < tuners_found; i++) {
656 msg.addr = tuner_addrs & 0xff;
657 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
658 if (ret == 1)
659 tuner_addrs = tuner_addrs >> 8;
660 else
661 break;
662 }
663 if (tuner_addrs == 0) {
664 tuner_addrs = 0x60;
665 tuner_info("could not clearly identify tuner address, "
666 "defaulting to %x\n", tuner_addrs);
667 } else {
668 tuner_addrs = tuner_addrs & 0xff;
669 tuner_info("setting tuner address to %x\n", tuner_addrs);
670 }
671 priv->tda827x_addr = tuner_addrs;
672 msg.addr = tuner_addrs;
673
Michael Krufky4e9154b2007-10-21 19:39:50 -0300674 tda8295_i2c_bridge(&t->fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300675 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300676 tda8295_i2c_bridge(&t->fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300677 if (ret != 1)
678 tuner_warn("TDA827x access failed!\n");
679 if ((data & 0x3c) == 0) {
680 strlcpy(t->i2c.name, "tda8295+18271", sizeof(t->i2c.name));
681 tda18271_attach(&t->fe, priv->tda827x_addr,
682 priv->i2c_props.adap);
683 priv->tda827x_ver = 4;
684 } else {
685 strlcpy(t->i2c.name, "tda8295+75a", sizeof(t->i2c.name));
686 tda827x_attach(&t->fe, priv->tda827x_addr,
687 priv->i2c_props.adap, &priv->cfg);
688
689 /* FIXME: tda827x module doesn't probe the tuner until
690 * tda827x_initial_sleep is called
691 */
692 if (t->fe.ops.tuner_ops.sleep)
693 t->fe.ops.tuner_ops.sleep(&t->fe);
694 priv->tda827x_ver = 2;
695 }
696 priv->tda827x_ver |= 1; /* signifies 8295 vs 8290 */
697 tuner_info("type set to %s\n", t->i2c.name);
698
Michael Krufky1dde7a42007-10-21 13:40:56 -0300699 t->fe.ops.analog_demod_ops = &tda8295_tuner_ops;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300700
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300701 t->mode = V4L2_TUNER_ANALOG_TV;
702
Michael Krufky4e9154b2007-10-21 19:39:50 -0300703 tda8295_init_if(&t->fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300704 return 0;
705}
706EXPORT_SYMBOL_GPL(tda8295_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Michael Krufky746d97322007-08-25 19:08:45 -0300708int tda8290_probe(struct tuner *t)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800709{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300710 struct tuner_i2c_props i2c_props = {
Michael Krufky746d97322007-08-25 19:08:45 -0300711 .adap = t->i2c.adapter,
712 .addr = t->i2c.addr
Michael Krufky910bb3e2007-08-27 21:22:20 -0300713 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300714
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300715 unsigned char soft_reset[] = { 0x00, 0x00 };
716 unsigned char easy_mode_b[] = { 0x01, 0x02 };
717 unsigned char easy_mode_g[] = { 0x01, 0x04 };
718 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800719 unsigned char addr_dto_lsb = 0x07;
720 unsigned char data;
721
Michael Krufky910bb3e2007-08-27 21:22:20 -0300722 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
723 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
724 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
725 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800726 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300727 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
728 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
729 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
730 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800731 if (data == 0x7b) {
732 return 0;
733 }
734 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300735 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800736 return -1;
737}
Michael Krufky910bb3e2007-08-27 21:22:20 -0300738EXPORT_SYMBOL_GPL(tda8290_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300739
740MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300741MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300742MODULE_LICENSE("GPL");
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * Overrides for Emacs so that we follow Linus's tabbing style.
746 * ---------------------------------------------------------------------------
747 * Local variables:
748 * c-basic-offset: 8
749 * End:
750 */