blob: 245b202560b566a896d4c87e2ecb00515fd2a482 [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
Hans Verkuil9dd659d2007-11-04 11:03:36 -030034#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 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;
117 struct tuner *t = priv->t;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300118 char* mode;
119
Michael Krufkyc7919d52007-12-08 17:06:30 -0300120 if (params->std & V4L2_STD_MN) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300121 priv->tda8290_easy_mode = 0x01;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300122 mode = "MN";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300123 } else if (params->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300124 priv->tda8290_easy_mode = 0x02;
125 mode = "B";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300126 } else if (params->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300127 priv->tda8290_easy_mode = 0x04;
128 mode = "GH";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300129 } else if (params->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300130 priv->tda8290_easy_mode = 0x08;
131 mode = "I";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300132 } else if (params->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300133 priv->tda8290_easy_mode = 0x10;
134 mode = "DK";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300135 } else if (params->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300136 priv->tda8290_easy_mode = 0x20;
137 mode = "L";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300138 } else if (params->std & V4L2_STD_SECAM_LC) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300139 priv->tda8290_easy_mode = 0x40;
140 mode = "LC";
141 } else {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300142 priv->tda8290_easy_mode = 0x10;
143 mode = "xx";
144 }
145
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300146 tuner_dbg("setting tda829x to system %s\n", mode);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300147}
148
Michael Krufkyc7919d52007-12-08 17:06:30 -0300149static void tda8290_set_params(struct dvb_frontend *fe,
150 struct analog_parameters *params)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300151{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300152 struct tda8290_priv *priv = fe->analog_demod_priv;
153 struct tuner *t = priv->t;
154
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800155 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300156 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800157 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200158 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800159 unsigned char gainset_off[] = { 0x28, 0x14 };
160 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
161 unsigned char adc_head_6[] = { 0x05, 0x04 };
162 unsigned char adc_head_9[] = { 0x05, 0x02 };
163 unsigned char adc_head_12[] = { 0x05, 0x01 };
164 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
165 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
166 unsigned char gainset_2[] = { 0x28, 0x64 };
167 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
168 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
169 unsigned char if_agc_set[] = { 0x0f, 0x81 };
170 unsigned char addr_adc_sat = 0x1a;
171 unsigned char addr_agc_stat = 0x1d;
172 unsigned char addr_pll_stat = 0x1b;
173 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800174 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300175 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800176
Michael Krufkyc7919d52007-12-08 17:06:30 -0300177 set_audio(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300178
179 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300180 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
181 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
182 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800183 msleep(1);
184
Michael Krufkyb2083192007-05-29 22:54:06 -0300185 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300186 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
187 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
188 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300189 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300190 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800191 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300192 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
193 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800194
Michael Krufky4e9154b2007-10-21 19:39:50 -0300195 tda8290_i2c_bridge(fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300196
Michael Krufky4e9154b2007-10-21 19:39:50 -0300197 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300198 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300199
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300200 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300201 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
202 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300203 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300204 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
205 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
206 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
207 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300208 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
209 break;
210 } else {
211 tuner_dbg("tda8290 not locked, no signal?\n");
212 msleep(100);
213 }
214 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800215 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800216 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
217 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
218 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300219 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800220 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300221 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
222 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
223 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
224 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800225 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800226 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
227 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300228 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300229 priv->cfg.agcf(fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800230 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300231 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
232 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
233 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
234 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800235 if((agc_stat > 115) || !(pll_stat & 0x80)) {
236 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300237 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
238 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800239 msleep(100);
240 }
241 }
242 }
243
244 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300245 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300246 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
247 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
248 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
249 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800250 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800251 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300252 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800253 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300254 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800255 }
256 }
257
Michael Krufky4e9154b2007-10-21 19:39:50 -0300258 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300259 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800260}
261
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800262/*---------------------------------------------------------------------*/
263
Michael Krufky4e9154b2007-10-21 19:39:50 -0300264static void tda8295_power(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300265{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300266 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300267 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
268
269 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
270 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
271
272 if (enable)
273 buf[1] = 0x01;
274 else
275 buf[1] = 0x03;
276
277 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
278}
279
Michael Krufky4e9154b2007-10-21 19:39:50 -0300280static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300281{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300282 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300283 unsigned char buf[] = { 0x01, 0x00 };
284
285 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
286 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
287
288 if (enable)
289 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
290 else
291 buf[1] = 0x00; /* reset active bit */
292
293 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
294}
295
Michael Krufky4e9154b2007-10-21 19:39:50 -0300296static void tda8295_set_video_std(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300297{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300298 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300299 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
300
301 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
302
Michael Krufky4e9154b2007-10-21 19:39:50 -0300303 tda8295_set_easy_mode(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300304 msleep(20);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300305 tda8295_set_easy_mode(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300306}
307
308/*---------------------------------------------------------------------*/
309
Michael Krufky4e9154b2007-10-21 19:39:50 -0300310static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300311{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300312 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300313 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
314
315 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
316 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
317
318 if (enable)
319 buf[1] &= ~0x40;
320 else
321 buf[1] |= 0x40;
322
323 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
324}
325
Michael Krufky4e9154b2007-10-21 19:39:50 -0300326static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300327{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300328 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300329 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
330 unsigned char set_gpio_val[] = { 0x46, 0x00 };
331
332 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
333 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
334 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
335 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
336
337 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
338
339 if (enable) {
340 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
341 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
342 }
343 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
344 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
345}
346
Michael Krufky4e9154b2007-10-21 19:39:50 -0300347static int tda8295_has_signal(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300348{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300349 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300350
351 unsigned char hvpll_stat = 0x26;
352 unsigned char ret;
353
354 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
355 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
356 return (ret & 0x01) ? 65535 : 0;
357}
358
359/*---------------------------------------------------------------------*/
360
Michael Krufkyc7919d52007-12-08 17:06:30 -0300361static void tda8295_set_params(struct dvb_frontend *fe,
362 struct analog_parameters *params)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300363{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300364 struct tda8290_priv *priv = fe->analog_demod_priv;
365 struct tuner *t = priv->t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300366
367 unsigned char blanking_mode[] = { 0x1d, 0x00 };
368
Michael Krufkyc7919d52007-12-08 17:06:30 -0300369 set_audio(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300370
Michael Krufkyc7919d52007-12-08 17:06:30 -0300371 tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300372
Michael Krufky4e9154b2007-10-21 19:39:50 -0300373 tda8295_power(fe, 1);
374 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300375
376 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
377 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
378
Michael Krufky4e9154b2007-10-21 19:39:50 -0300379 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300380
381 blanking_mode[1] = 0x03;
382 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
383 msleep(20);
384
Michael Krufky4e9154b2007-10-21 19:39:50 -0300385 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300386
Michael Krufky4e9154b2007-10-21 19:39:50 -0300387 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300388 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300389
390 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300391 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300392
Michael Krufky4e9154b2007-10-21 19:39:50 -0300393 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300394 tuner_dbg("tda8295 is locked\n");
395 else
396 tuner_dbg("tda8295 not locked, no signal?\n");
397
Michael Krufky4e9154b2007-10-21 19:39:50 -0300398 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300399}
400
401/*---------------------------------------------------------------------*/
402
Michael Krufky4e9154b2007-10-21 19:39:50 -0300403static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300405 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 unsigned char i2c_get_afc[1] = { 0x1B };
408 unsigned char afc = 0;
409
Michael Krufkydb8a6952007-08-21 01:24:42 -0300410 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
411 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300412 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300413}
414
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800415/*---------------------------------------------------------------------*/
416
Michael Krufky4e9154b2007-10-21 19:39:50 -0300417static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700418{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300419 struct tda8290_priv *priv = fe->analog_demod_priv;
420
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800421 unsigned char cb1[] = { 0x30, 0xD0 };
422 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200423 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300424 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800425
Michael Krufky4e9154b2007-10-21 19:39:50 -0300426 tda8290_i2c_bridge(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300427 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800428 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300429 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300430 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300431 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
432 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700433}
434
Michael Krufky4e9154b2007-10-21 19:39:50 -0300435static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300436{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300437 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300438
Michael Krufky4e9154b2007-10-21 19:39:50 -0300439 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300440}
441
Michael Krufky4e9154b2007-10-21 19:39:50 -0300442static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800443{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300444 struct tda8290_priv *priv = fe->analog_demod_priv;
445 struct tuner *t = priv->t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300446
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800447 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300448 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800449 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
450
Michael Krufky746d97322007-08-25 19:08:45 -0300451 if ((t->config == 1) || (t->config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300452 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300453 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300454 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
455 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800456}
457
Michael Krufky4e9154b2007-10-21 19:39:50 -0300458static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300459{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300460 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300461
462 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
463 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
464 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
465 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
466 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
467 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
468 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
469
Michael Krufky4e9154b2007-10-21 19:39:50 -0300470 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300471
Michael Krufky4e9154b2007-10-21 19:39:50 -0300472 tda8295_set_easy_mode(fe, 0);
473 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300474
475 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
476 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
477 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
478 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
479 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
480 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
481 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
482
Michael Krufky4e9154b2007-10-21 19:39:50 -0300483 tda8295_agc1_out(fe, 0);
484 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300485}
486
Michael Krufky4e9154b2007-10-21 19:39:50 -0300487static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800488{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300489 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800490 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800491 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800492 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800493 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300494 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800495 .buf=tda8275_init, .len = 14};
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300496 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800497 msg.buf = tda8275a_init;
498
Michael Krufky4e9154b2007-10-21 19:39:50 -0300499 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300500 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300501 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800502}
503
504/*---------------------------------------------------------------------*/
505
Michael Krufky4e9154b2007-10-21 19:39:50 -0300506static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300507{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300508 if (fe->ops.tuner_ops.release)
509 fe->ops.tuner_ops.release(fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300510
Michael Krufky4e9154b2007-10-21 19:39:50 -0300511 kfree(fe->analog_demod_priv);
512 fe->analog_demod_priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300513}
514
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300515static int tda829x_find_tuner(struct dvb_frontend *fe)
516{
517 struct tda8290_priv *priv = fe->analog_demod_priv;
518 struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
519 struct tuner *t = priv->t;
520 int i, ret, tuners_found;
521 u32 tuner_addrs;
522 u8 data;
523 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
524
525 if (NULL == ops)
526 return -EINVAL;
527
528 ops->i2c_gate_ctrl(fe, 1);
529
530 /* probe for tuner chip */
531 tuners_found = 0;
532 tuner_addrs = 0;
533 for (i = 0x60; i <= 0x63; i++) {
534 msg.addr = i;
535 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
536 if (ret == 1) {
537 tuners_found++;
538 tuner_addrs = (tuner_addrs << 8) + i;
539 }
540 }
541 /* if there is more than one tuner, we expect the right one is
542 behind the bridge and we choose the highest address that doesn't
543 give a response now
544 */
545
546 ops->i2c_gate_ctrl(fe, 0);
547
548 if (tuners_found > 1)
549 for (i = 0; i < tuners_found; i++) {
550 msg.addr = tuner_addrs & 0xff;
551 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
552 if (ret == 1)
553 tuner_addrs = tuner_addrs >> 8;
554 else
555 break;
556 }
557
558 if (tuner_addrs == 0) {
559 tuner_addrs = 0x60;
560 tuner_info("could not clearly identify tuner address, "
561 "defaulting to %x\n", tuner_addrs);
562 } else {
563 tuner_addrs = tuner_addrs & 0xff;
564 tuner_info("setting tuner address to %x\n", tuner_addrs);
565 }
566 priv->tda827x_addr = tuner_addrs;
567 msg.addr = tuner_addrs;
568
569 ops->i2c_gate_ctrl(fe, 1);
570 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
571
572 if (ret != 1) {
573 tuner_warn("tuner access failed!\n");
574 return -EREMOTEIO;
575 }
576
577 if (data == 0x83) {
578 priv->ver |= TDA18271;
Michael Krufky68816472007-12-08 16:25:41 -0300579 tda18271_attach(fe, priv->tda827x_addr,
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300580 priv->i2c_props.adap);
581 } else {
582 if ((data & 0x3c) == 0)
583 priv->ver |= TDA8275;
584 else
585 priv->ver |= TDA8275A;
586
Michael Krufky68816472007-12-08 16:25:41 -0300587 tda827x_attach(fe, priv->tda827x_addr,
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300588 priv->i2c_props.adap, &priv->cfg);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300589 }
Michael Krufky68816472007-12-08 16:25:41 -0300590 if (fe->ops.tuner_ops.init)
591 fe->ops.tuner_ops.init(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300592
Michael Krufky68816472007-12-08 16:25:41 -0300593 if (fe->ops.tuner_ops.sleep)
594 fe->ops.tuner_ops.sleep(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300595
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300596 ops->i2c_gate_ctrl(fe, 0);
597
598 switch (priv->ver) {
599 case TDA8290 | TDA8275:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300600 strlcpy(t->i2c->name, "tda8290+75", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300601 break;
602 case TDA8295 | TDA8275:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300603 strlcpy(t->i2c->name, "tda8295+75", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300604 break;
605 case TDA8290 | TDA8275A:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300606 strlcpy(t->i2c->name, "tda8290+75a", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300607 break;
608 case TDA8295 | TDA8275A:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300609 strlcpy(t->i2c->name, "tda8295+75a", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300610 break;
611 case TDA8290 | TDA18271:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300612 strlcpy(t->i2c->name, "tda8290+18271", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300613 break;
614 case TDA8295 | TDA18271:
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300615 strlcpy(t->i2c->name, "tda8295+18271", sizeof(t->i2c->name));
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300616 break;
617 default:
618 return -EINVAL;
619 }
620
621 return 0;
622}
623
Michael Krufkyf1f32842007-11-03 22:14:54 -0300624static int tda8290_probe(struct tuner_i2c_props *i2c_props)
625{
626#define TDA8290_ID 0x89
627 unsigned char tda8290_id[] = { 0x1f, 0x00 };
628
629 /* detect tda8290 */
630 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
631 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
632
633 if (tda8290_id[1] == TDA8290_ID) {
634 if (tuner_debug)
635 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
636 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
637 i2c_props->addr);
638 return 0;
639 }
640
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300641 return -ENODEV;
Michael Krufkyf1f32842007-11-03 22:14:54 -0300642}
643
644static int tda8295_probe(struct tuner_i2c_props *i2c_props)
645{
646#define TDA8295_ID 0x8a
647 unsigned char tda8295_id[] = { 0x2f, 0x00 };
648
649 /* detect tda8295 */
650 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
651 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
652
653 if (tda8295_id[1] == TDA8295_ID) {
654 if (tuner_debug)
655 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
656 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
657 i2c_props->addr);
658 return 0;
659 }
660
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300661 return -ENODEV;
Michael Krufkyf1f32842007-11-03 22:14:54 -0300662}
663
Michael Krufky1dde7a42007-10-21 13:40:56 -0300664static struct analog_tuner_ops tda8290_tuner_ops = {
Michael Krufkyc7919d52007-12-08 17:06:30 -0300665 .set_params = tda8290_set_params,
Michael Krufky746d97322007-08-25 19:08:45 -0300666 .has_signal = tda8290_has_signal,
667 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300668 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300669 .i2c_gate_ctrl = tda8290_i2c_bridge,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300670};
671
Michael Krufky1dde7a42007-10-21 13:40:56 -0300672static struct analog_tuner_ops tda8295_tuner_ops = {
Michael Krufkyc7919d52007-12-08 17:06:30 -0300673 .set_params = tda8295_set_params,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300674 .has_signal = tda8295_has_signal,
675 .standby = tda8295_standby,
676 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300677 .i2c_gate_ctrl = tda8295_i2c_bridge,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300678};
679
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300680int tda829x_attach(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300682 struct dvb_frontend *fe = &t->fe;
Michael Krufkyb2083192007-05-29 22:54:06 -0300683 struct tda8290_priv *priv = NULL;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300684
Michael Krufkyb2083192007-05-29 22:54:06 -0300685 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
686 if (priv == NULL)
Michael Krufky746d97322007-08-25 19:08:45 -0300687 return -ENOMEM;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300688 fe->analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300689
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300690 priv->i2c_props.addr = t->i2c->addr;
691 priv->i2c_props.adap = t->i2c->adapter;
Michael Krufky746d97322007-08-25 19:08:45 -0300692 priv->cfg.config = &t->config;
693 priv->cfg.tuner_callback = t->tuner_callback;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300694 priv->t = t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300695
Michael Krufkyf1f32842007-11-03 22:14:54 -0300696 if (tda8290_probe(&priv->i2c_props) == 0) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300697 priv->ver = TDA8290;
698 fe->ops.analog_demod_ops = &tda8290_tuner_ops;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800699 }
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300700
Michael Krufkyf1f32842007-11-03 22:14:54 -0300701 if (tda8295_probe(&priv->i2c_props) == 0) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300702 priv->ver = TDA8295;
703 fe->ops.analog_demod_ops = &tda8295_tuner_ops;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800704 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800705
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300706 if (tda829x_find_tuner(fe) < 0)
707 return -EINVAL;
Michael Krufky746d97322007-08-25 19:08:45 -0300708
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300709 if (priv->ver & TDA8290) {
710 tda8290_init_tuner(fe);
711 tda8290_init_if(fe);
712 } else if (priv->ver & TDA8295)
713 tda8295_init_if(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300714
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300715 tuner_info("type set to %s\n", t->i2c->name);
Michael Krufky746d97322007-08-25 19:08:45 -0300716
Michael Krufky746d97322007-08-25 19:08:45 -0300717 t->mode = V4L2_TUNER_ANALOG_TV;
718
Michael Krufky746d97322007-08-25 19:08:45 -0300719 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300721EXPORT_SYMBOL_GPL(tda829x_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Michael Krufkyf1f32842007-11-03 22:14:54 -0300723int tda829x_probe(struct tuner *t)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800724{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300725 struct tuner_i2c_props i2c_props = {
Hans Verkuil1cba97d72007-09-14 05:13:54 -0300726 .adap = t->i2c->adapter,
727 .addr = t->i2c->addr
Michael Krufky910bb3e2007-08-27 21:22:20 -0300728 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300729
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300730 unsigned char soft_reset[] = { 0x00, 0x00 };
731 unsigned char easy_mode_b[] = { 0x01, 0x02 };
732 unsigned char easy_mode_g[] = { 0x01, 0x04 };
733 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800734 unsigned char addr_dto_lsb = 0x07;
735 unsigned char data;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300736#define PROBE_BUFFER_SIZE 8
737 unsigned char buf[PROBE_BUFFER_SIZE];
738 int i;
739
740 /* rule out tda9887, which would return the same byte repeatedly */
741 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
742 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
743 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
Michael Krufkybbe1e0b2007-11-05 09:54:42 -0300744 if (buf[i] != buf[0])
745 break;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300746 }
747
748 /* all bytes are equal, not a tda829x - probably a tda9887 */
749 if (i == PROBE_BUFFER_SIZE)
750 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800751
Michael Krufkyf1f32842007-11-03 22:14:54 -0300752 if ((tda8290_probe(&i2c_props) == 0) ||
753 (tda8295_probe(&i2c_props) == 0))
754 return 0;
755
756 /* fall back to old probing method */
Michael Krufky910bb3e2007-08-27 21:22:20 -0300757 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
758 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
759 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
760 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800761 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300762 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
763 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
764 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
765 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800766 if (data == 0x7b) {
767 return 0;
768 }
769 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300770 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300771 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800772}
Michael Krufkyf1f32842007-11-03 22:14:54 -0300773EXPORT_SYMBOL_GPL(tda829x_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300774
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300775MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300776MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300777MODULE_LICENSE("GPL");
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*
780 * Overrides for Emacs so that we follow Linus's tabbing style.
781 * ---------------------------------------------------------------------------
782 * Local variables:
783 * c-basic-offset: 8
784 * End:
785 */