blob: a451d9480c1d453043e208a5dbc28767fa6cae7b [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 Krufkyab166052007-12-09 02:26:48 -030026#include "tuner-driver.h"
27#include "tuner-i2c.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030028#include "tda8290.h"
Michael Krufky746d97322007-08-25 19:08:45 -030029#include "tda827x.h"
Michael Krufky5bea1cd2007-10-22 09:56:38 -030030#include "tda18271.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030031
Michael Krufkyab166052007-12-09 02:26:48 -030032static int debug;
33module_param(debug, int, 0644);
Michael Krufky910bb3e2007-08-27 21:22:20 -030034MODULE_PARM_DESC(debug, "enable verbose debug messages");
35
Hans Verkuil9dd659d2007-11-04 11:03:36 -030036#define PREFIX "tda8290"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/* ---------------------------------------------------------------------- */
39
Michael Krufkyb2083192007-05-29 22:54:06 -030040struct tda8290_priv {
Michael Krufkydb8a6952007-08-21 01:24:42 -030041 struct tuner_i2c_props i2c_props;
42
Michael Krufkyb2083192007-05-29 22:54:06 -030043 unsigned char tda8290_easy_mode;
Michael Krufky746d97322007-08-25 19:08:45 -030044
Michael Krufkyb2083192007-05-29 22:54:06 -030045 unsigned char tda827x_addr;
Michael Krufky8c125f2c2007-10-27 02:00:57 -030046
47 unsigned char ver;
48#define TDA8290 1
49#define TDA8295 2
50#define TDA8275 4
51#define TDA8275A 8
52#define TDA18271 16
Michael Krufky910bb3e2007-08-27 21:22:20 -030053
Michael Krufky746d97322007-08-25 19:08:45 -030054 struct tda827x_config cfg;
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 Krufkyc7919d52007-12-08 17:06:30 -0300113static void set_audio(struct dvb_frontend *fe,
114 struct analog_parameters *params)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800115{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300116 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300117 char* mode;
118
Michael Krufkyc7919d52007-12-08 17:06:30 -0300119 if (params->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 Krufkyc7919d52007-12-08 17:06:30 -0300122 } else if (params->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300123 priv->tda8290_easy_mode = 0x02;
124 mode = "B";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300125 } else if (params->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300126 priv->tda8290_easy_mode = 0x04;
127 mode = "GH";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300128 } else if (params->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300129 priv->tda8290_easy_mode = 0x08;
130 mode = "I";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300131 } else if (params->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300132 priv->tda8290_easy_mode = 0x10;
133 mode = "DK";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300134 } else if (params->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300135 priv->tda8290_easy_mode = 0x20;
136 mode = "L";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300137 } else if (params->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 Krufkyc7919d52007-12-08 17:06:30 -0300148static void tda8290_set_params(struct dvb_frontend *fe,
149 struct analog_parameters *params)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300150{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300151 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300152
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 Krufkyc7919d52007-12-08 17:06:30 -0300175 set_audio(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300176
Michael Krufkyab166052007-12-09 02:26:48 -0300177 if (priv->cfg.config)
178 tuner_dbg("tda827xa config is 0x%02x\n", *priv->cfg.config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300179 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
180 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
181 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800182 msleep(1);
183
Michael Krufkyb2083192007-05-29 22:54:06 -0300184 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300185 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
186 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
187 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300188 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300189 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800190 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300191 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
192 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800193
Michael Krufky4e9154b2007-10-21 19:39:50 -0300194 tda8290_i2c_bridge(fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300195
Michael Krufky4e9154b2007-10-21 19:39:50 -0300196 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300197 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300198
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300199 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300200 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
201 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300202 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300203 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
204 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
205 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
206 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300207 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
208 break;
209 } else {
210 tuner_dbg("tda8290 not locked, no signal?\n");
211 msleep(100);
212 }
213 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800214 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800215 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
216 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
217 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300218 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800219 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300220 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
221 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
222 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
223 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800224 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800225 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
226 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300227 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300228 priv->cfg.agcf(fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800229 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300230 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
231 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
232 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
233 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800234 if((agc_stat > 115) || !(pll_stat & 0x80)) {
235 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300236 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
237 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800238 msleep(100);
239 }
240 }
241 }
242
243 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300244 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300245 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
246 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
247 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
248 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800249 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800250 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300251 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800252 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300253 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800254 }
255 }
256
Michael Krufky4e9154b2007-10-21 19:39:50 -0300257 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300258 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800259}
260
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800261/*---------------------------------------------------------------------*/
262
Michael Krufky4e9154b2007-10-21 19:39:50 -0300263static void tda8295_power(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300264{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300265 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300266 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
267
268 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
269 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
270
271 if (enable)
272 buf[1] = 0x01;
273 else
274 buf[1] = 0x03;
275
276 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
277}
278
Michael Krufky4e9154b2007-10-21 19:39:50 -0300279static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300280{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300281 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300282 unsigned char buf[] = { 0x01, 0x00 };
283
284 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
285 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
286
287 if (enable)
288 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
289 else
290 buf[1] = 0x00; /* reset active bit */
291
292 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
293}
294
Michael Krufky4e9154b2007-10-21 19:39:50 -0300295static void tda8295_set_video_std(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300296{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300297 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300298 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
299
300 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
301
Michael Krufky4e9154b2007-10-21 19:39:50 -0300302 tda8295_set_easy_mode(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300303 msleep(20);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300304 tda8295_set_easy_mode(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300305}
306
307/*---------------------------------------------------------------------*/
308
Michael Krufky4e9154b2007-10-21 19:39:50 -0300309static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300310{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300311 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300312 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
313
314 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
315 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
316
317 if (enable)
318 buf[1] &= ~0x40;
319 else
320 buf[1] |= 0x40;
321
322 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
323}
324
Michael Krufky4e9154b2007-10-21 19:39:50 -0300325static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300326{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300327 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300328 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
329 unsigned char set_gpio_val[] = { 0x46, 0x00 };
330
331 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
332 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
333 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
334 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
335
336 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
337
338 if (enable) {
339 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
340 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
341 }
342 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
343 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
344}
345
Michael Krufky4e9154b2007-10-21 19:39:50 -0300346static int tda8295_has_signal(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300347{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300348 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300349
350 unsigned char hvpll_stat = 0x26;
351 unsigned char ret;
352
353 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
354 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
355 return (ret & 0x01) ? 65535 : 0;
356}
357
358/*---------------------------------------------------------------------*/
359
Michael Krufkyc7919d52007-12-08 17:06:30 -0300360static void tda8295_set_params(struct dvb_frontend *fe,
361 struct analog_parameters *params)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300362{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300363 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300364
365 unsigned char blanking_mode[] = { 0x1d, 0x00 };
366
Michael Krufkyc7919d52007-12-08 17:06:30 -0300367 set_audio(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300368
Michael Krufkyc7919d52007-12-08 17:06:30 -0300369 tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300370
Michael Krufky4e9154b2007-10-21 19:39:50 -0300371 tda8295_power(fe, 1);
372 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300373
374 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
375 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
376
Michael Krufky4e9154b2007-10-21 19:39:50 -0300377 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300378
379 blanking_mode[1] = 0x03;
380 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
381 msleep(20);
382
Michael Krufky4e9154b2007-10-21 19:39:50 -0300383 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300384
Michael Krufky4e9154b2007-10-21 19:39:50 -0300385 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300386 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300387
388 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300389 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300390
Michael Krufky4e9154b2007-10-21 19:39:50 -0300391 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300392 tuner_dbg("tda8295 is locked\n");
393 else
394 tuner_dbg("tda8295 not locked, no signal?\n");
395
Michael Krufky4e9154b2007-10-21 19:39:50 -0300396 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300397}
398
399/*---------------------------------------------------------------------*/
400
Michael Krufky4e9154b2007-10-21 19:39:50 -0300401static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300403 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 unsigned char i2c_get_afc[1] = { 0x1B };
406 unsigned char afc = 0;
407
Michael Krufkydb8a6952007-08-21 01:24:42 -0300408 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
409 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300410 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300411}
412
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800413/*---------------------------------------------------------------------*/
414
Michael Krufky4e9154b2007-10-21 19:39:50 -0300415static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700416{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300417 struct tda8290_priv *priv = fe->analog_demod_priv;
418
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800419 unsigned char cb1[] = { 0x30, 0xD0 };
420 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200421 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300422 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800423
Michael Krufky4e9154b2007-10-21 19:39:50 -0300424 tda8290_i2c_bridge(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300425 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800426 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300427 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300428 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300429 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
430 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700431}
432
Michael Krufky4e9154b2007-10-21 19:39:50 -0300433static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300434{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300435 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300436
Michael Krufky4e9154b2007-10-21 19:39:50 -0300437 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300438}
439
Michael Krufky4e9154b2007-10-21 19:39:50 -0300440static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800441{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300442 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300443
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800444 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300445 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800446 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
447
Michael Krufkyab166052007-12-09 02:26:48 -0300448 if ((priv->cfg.config) &&
449 ((*priv->cfg.config == 1) || (*priv->cfg.config == 2)))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300450 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300451 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300452 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
453 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800454}
455
Michael Krufky4e9154b2007-10-21 19:39:50 -0300456static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300457{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300458 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300459
460 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
461 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
462 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
463 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
464 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
465 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
466 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
467
Michael Krufky4e9154b2007-10-21 19:39:50 -0300468 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300469
Michael Krufky4e9154b2007-10-21 19:39:50 -0300470 tda8295_set_easy_mode(fe, 0);
471 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300472
473 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
476 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
477 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
478 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
479 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
480
Michael Krufky4e9154b2007-10-21 19:39:50 -0300481 tda8295_agc1_out(fe, 0);
482 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300483}
484
Michael Krufky4e9154b2007-10-21 19:39:50 -0300485static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800486{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300487 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800488 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800489 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800490 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800491 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300492 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800493 .buf=tda8275_init, .len = 14};
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300494 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800495 msg.buf = tda8275a_init;
496
Michael Krufky4e9154b2007-10-21 19:39:50 -0300497 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300498 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300499 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800500}
501
502/*---------------------------------------------------------------------*/
503
Michael Krufky4e9154b2007-10-21 19:39:50 -0300504static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300505{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300506 if (fe->ops.tuner_ops.release)
507 fe->ops.tuner_ops.release(fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300508
Michael Krufky4e9154b2007-10-21 19:39:50 -0300509 kfree(fe->analog_demod_priv);
510 fe->analog_demod_priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300511}
512
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300513static int tda829x_find_tuner(struct dvb_frontend *fe)
514{
515 struct tda8290_priv *priv = fe->analog_demod_priv;
516 struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300517 int i, ret, tuners_found;
518 u32 tuner_addrs;
519 u8 data;
520 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
521
522 if (NULL == ops)
523 return -EINVAL;
524
525 ops->i2c_gate_ctrl(fe, 1);
526
527 /* probe for tuner chip */
528 tuners_found = 0;
529 tuner_addrs = 0;
530 for (i = 0x60; i <= 0x63; i++) {
531 msg.addr = i;
532 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
533 if (ret == 1) {
534 tuners_found++;
535 tuner_addrs = (tuner_addrs << 8) + i;
536 }
537 }
538 /* if there is more than one tuner, we expect the right one is
539 behind the bridge and we choose the highest address that doesn't
540 give a response now
541 */
542
543 ops->i2c_gate_ctrl(fe, 0);
544
545 if (tuners_found > 1)
546 for (i = 0; i < tuners_found; i++) {
547 msg.addr = tuner_addrs & 0xff;
548 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
549 if (ret == 1)
550 tuner_addrs = tuner_addrs >> 8;
551 else
552 break;
553 }
554
555 if (tuner_addrs == 0) {
556 tuner_addrs = 0x60;
557 tuner_info("could not clearly identify tuner address, "
558 "defaulting to %x\n", tuner_addrs);
559 } else {
560 tuner_addrs = tuner_addrs & 0xff;
561 tuner_info("setting tuner address to %x\n", tuner_addrs);
562 }
563 priv->tda827x_addr = tuner_addrs;
564 msg.addr = tuner_addrs;
565
566 ops->i2c_gate_ctrl(fe, 1);
567 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
568
569 if (ret != 1) {
570 tuner_warn("tuner access failed!\n");
571 return -EREMOTEIO;
572 }
573
574 if (data == 0x83) {
575 priv->ver |= TDA18271;
Michael Krufky68816472007-12-08 16:25:41 -0300576 tda18271_attach(fe, priv->tda827x_addr,
Michael Krufkye435f952007-12-09 22:23:30 -0300577 priv->i2c_props.adap,
578 TDA18271_GATE_ANALOG);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300579 } else {
580 if ((data & 0x3c) == 0)
581 priv->ver |= TDA8275;
582 else
583 priv->ver |= TDA8275A;
584
Michael Krufky68816472007-12-08 16:25:41 -0300585 tda827x_attach(fe, priv->tda827x_addr,
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300586 priv->i2c_props.adap, &priv->cfg);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300587 }
Michael Krufky68816472007-12-08 16:25:41 -0300588 if (fe->ops.tuner_ops.init)
589 fe->ops.tuner_ops.init(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300590
Michael Krufky68816472007-12-08 16:25:41 -0300591 if (fe->ops.tuner_ops.sleep)
592 fe->ops.tuner_ops.sleep(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300593
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300594 ops->i2c_gate_ctrl(fe, 0);
595
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300596 return 0;
597}
598
Michael Krufkyf1f32842007-11-03 22:14:54 -0300599static int tda8290_probe(struct tuner_i2c_props *i2c_props)
600{
601#define TDA8290_ID 0x89
602 unsigned char tda8290_id[] = { 0x1f, 0x00 };
603
604 /* detect tda8290 */
605 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
606 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
607
608 if (tda8290_id[1] == TDA8290_ID) {
Michael Krufkyab166052007-12-09 02:26:48 -0300609 if (debug)
Michael Krufkyf1f32842007-11-03 22:14:54 -0300610 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
611 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
612 i2c_props->addr);
613 return 0;
614 }
615
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300616 return -ENODEV;
Michael Krufkyf1f32842007-11-03 22:14:54 -0300617}
618
619static int tda8295_probe(struct tuner_i2c_props *i2c_props)
620{
621#define TDA8295_ID 0x8a
622 unsigned char tda8295_id[] = { 0x2f, 0x00 };
623
624 /* detect tda8295 */
625 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
626 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
627
628 if (tda8295_id[1] == TDA8295_ID) {
Michael Krufkyab166052007-12-09 02:26:48 -0300629 if (debug)
Michael Krufkyf1f32842007-11-03 22:14:54 -0300630 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
631 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
632 i2c_props->addr);
633 return 0;
634 }
635
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300636 return -ENODEV;
Michael Krufkyf1f32842007-11-03 22:14:54 -0300637}
638
Michael Krufky1dde7a42007-10-21 13:40:56 -0300639static struct analog_tuner_ops tda8290_tuner_ops = {
Michael Krufkya55db8c2007-12-09 13:52:51 -0300640 .info = {
641 .name = "TDA8290",
642 },
Michael Krufkyc7919d52007-12-08 17:06:30 -0300643 .set_params = tda8290_set_params,
Michael Krufky746d97322007-08-25 19:08:45 -0300644 .has_signal = tda8290_has_signal,
645 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300646 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300647 .i2c_gate_ctrl = tda8290_i2c_bridge,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300648};
649
Michael Krufky1dde7a42007-10-21 13:40:56 -0300650static struct analog_tuner_ops tda8295_tuner_ops = {
Michael Krufkya55db8c2007-12-09 13:52:51 -0300651 .info = {
652 .name = "TDA8295",
653 },
Michael Krufkyc7919d52007-12-08 17:06:30 -0300654 .set_params = tda8295_set_params,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300655 .has_signal = tda8295_has_signal,
656 .standby = tda8295_standby,
657 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300658 .i2c_gate_ctrl = tda8295_i2c_bridge,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300659};
660
Michael Krufkyab166052007-12-09 02:26:48 -0300661struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
662 struct i2c_adapter *i2c_adap, u8 i2c_addr,
663 struct tda829x_config *cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Michael Krufkyb2083192007-05-29 22:54:06 -0300665 struct tda8290_priv *priv = NULL;
Michael Krufkyab166052007-12-09 02:26:48 -0300666 char *name;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300667
Michael Krufkyb2083192007-05-29 22:54:06 -0300668 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
669 if (priv == NULL)
Michael Krufkyab166052007-12-09 02:26:48 -0300670 return NULL;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300671 fe->analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300672
Michael Krufkyab166052007-12-09 02:26:48 -0300673 priv->i2c_props.addr = i2c_addr;
674 priv->i2c_props.adap = i2c_adap;
675 if (cfg) {
676 priv->cfg.config = cfg->lna_cfg;
677 priv->cfg.tuner_callback = cfg->tuner_callback;
678 }
Michael Krufkydb8a6952007-08-21 01:24:42 -0300679
Michael Krufkyf1f32842007-11-03 22:14:54 -0300680 if (tda8290_probe(&priv->i2c_props) == 0) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300681 priv->ver = TDA8290;
682 fe->ops.analog_demod_ops = &tda8290_tuner_ops;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800683 }
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300684
Michael Krufkyf1f32842007-11-03 22:14:54 -0300685 if (tda8295_probe(&priv->i2c_props) == 0) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300686 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)
Michael Krufkyfa746aee2007-12-09 05:16:10 -0300691 goto fail;
Michael Krufky746d97322007-08-25 19:08:45 -0300692
Michael Krufkyab166052007-12-09 02:26:48 -0300693 switch (priv->ver) {
694 case TDA8290 | TDA8275:
695 name = "tda8290+75";
696 break;
697 case TDA8295 | TDA8275:
698 name = "tda8295+75";
699 break;
700 case TDA8290 | TDA8275A:
701 name = "tda8290+75a";
702 break;
703 case TDA8295 | TDA8275A:
704 name = "tda8295+75a";
705 break;
706 case TDA8290 | TDA18271:
707 name = "tda8290+18271";
708 break;
709 case TDA8295 | TDA18271:
710 name = "tda8295+18271";
711 break;
712 default:
713 goto fail;
714 }
715 tuner_info("type set to %s\n", name);
716
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300717 if (priv->ver & TDA8290) {
718 tda8290_init_tuner(fe);
719 tda8290_init_if(fe);
720 } else if (priv->ver & TDA8295)
721 tda8295_init_if(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300722
Michael Krufkyab166052007-12-09 02:26:48 -0300723 return fe;
Michael Krufkyfa746aee2007-12-09 05:16:10 -0300724
725fail:
726 tda829x_release(fe);
727 fe->ops.analog_demod_ops = NULL;
Michael Krufkyab166052007-12-09 02:26:48 -0300728 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300730EXPORT_SYMBOL_GPL(tda829x_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Michael Krufkyab166052007-12-09 02:26:48 -0300732int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800733{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300734 struct tuner_i2c_props i2c_props = {
Michael Krufkyab166052007-12-09 02:26:48 -0300735 .adap = i2c_adap,
736 .addr = i2c_addr,
Michael Krufky910bb3e2007-08-27 21:22:20 -0300737 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300738
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300739 unsigned char soft_reset[] = { 0x00, 0x00 };
740 unsigned char easy_mode_b[] = { 0x01, 0x02 };
741 unsigned char easy_mode_g[] = { 0x01, 0x04 };
742 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800743 unsigned char addr_dto_lsb = 0x07;
744 unsigned char data;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300745#define PROBE_BUFFER_SIZE 8
746 unsigned char buf[PROBE_BUFFER_SIZE];
747 int i;
748
749 /* rule out tda9887, which would return the same byte repeatedly */
750 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
751 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
752 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
Michael Krufkybbe1e0b2007-11-05 09:54:42 -0300753 if (buf[i] != buf[0])
754 break;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300755 }
756
757 /* all bytes are equal, not a tda829x - probably a tda9887 */
758 if (i == PROBE_BUFFER_SIZE)
759 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800760
Michael Krufkyf1f32842007-11-03 22:14:54 -0300761 if ((tda8290_probe(&i2c_props) == 0) ||
762 (tda8295_probe(&i2c_props) == 0))
763 return 0;
764
765 /* fall back to old probing method */
Michael Krufky910bb3e2007-08-27 21:22:20 -0300766 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
767 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
768 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
769 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800770 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300771 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
772 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
773 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
774 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800775 if (data == 0x7b) {
776 return 0;
777 }
778 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300779 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300780 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800781}
Michael Krufkyf1f32842007-11-03 22:14:54 -0300782EXPORT_SYMBOL_GPL(tda829x_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300783
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300784MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300785MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300786MODULE_LICENSE("GPL");
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/*
789 * Overrides for Emacs so that we follow Linus's tabbing style.
790 * ---------------------------------------------------------------------------
791 * Local variables:
792 * c-basic-offset: 8
793 * End:
794 */