blob: 0ebb5b525e576da86f021b74b669f5493e4886db [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-i2c.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030027#include "tda8290.h"
Michael Krufky746d97322007-08-25 19:08:45 -030028#include "tda827x.h"
Michael Krufky5bea1cd2007-10-22 09:56:38 -030029#include "tda18271.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030030
Michael Krufkyab166052007-12-09 02:26:48 -030031static int debug;
32module_param(debug, int, 0644);
Michael Krufky910bb3e2007-08-27 21:22:20 -030033MODULE_PARM_DESC(debug, "enable verbose debug messages");
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* ---------------------------------------------------------------------- */
36
Michael Krufkyb2083192007-05-29 22:54:06 -030037struct tda8290_priv {
Michael Krufkydb8a6952007-08-21 01:24:42 -030038 struct tuner_i2c_props i2c_props;
39
Michael Krufkyb2083192007-05-29 22:54:06 -030040 unsigned char tda8290_easy_mode;
Michael Krufky746d97322007-08-25 19:08:45 -030041
Michael Krufkyb2083192007-05-29 22:54:06 -030042 unsigned char tda827x_addr;
Michael Krufky8c125f2c2007-10-27 02:00:57 -030043
44 unsigned char ver;
45#define TDA8290 1
46#define TDA8295 2
47#define TDA8275 4
48#define TDA8275A 8
49#define TDA18271 16
Michael Krufky910bb3e2007-08-27 21:22:20 -030050
Michael Krufky746d97322007-08-25 19:08:45 -030051 struct tda827x_config cfg;
Michael Krufkyb2083192007-05-29 22:54:06 -030052};
53
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080054/*---------------------------------------------------------------------*/
55
Michael Krufkya72dd302007-10-24 09:30:17 -030056static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080057{
Michael Krufky4e9154b2007-10-21 19:39:50 -030058 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -030059
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080060 unsigned char enable[2] = { 0x21, 0xC0 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -020061 unsigned char disable[2] = { 0x21, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080062 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030063
64 if (close) {
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080065 msg = enable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030066 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080067 /* let the bridge stabilize */
68 msleep(20);
69 } else {
70 msg = disable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030071 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080072 }
Michael Krufkya72dd302007-10-24 09:30:17 -030073
74 return 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080075}
76
Michael Krufkya72dd302007-10-24 09:30:17 -030077static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
Michael Krufky5bea1cd2007-10-22 09:56:38 -030078{
Michael Krufky4e9154b2007-10-21 19:39:50 -030079 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -030080
81 unsigned char enable[2] = { 0x45, 0xc1 };
82 unsigned char disable[2] = { 0x46, 0x00 };
83 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
84 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030085
Michael Krufky5bea1cd2007-10-22 09:56:38 -030086 if (close) {
87 msg = enable;
88 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
89 /* let the bridge stabilize */
90 msleep(20);
91 } else {
92 msg = disable;
93 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
94 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
95
96 buf[2] = msg[1];
97 buf[2] &= ~0x04;
98 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
99 msleep(5);
100
101 msg[1] |= 0x04;
102 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
103 }
Michael Krufkya72dd302007-10-24 09:30:17 -0300104
105 return 0;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300106}
107
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800108/*---------------------------------------------------------------------*/
109
Michael Krufkyc7919d52007-12-08 17:06:30 -0300110static void set_audio(struct dvb_frontend *fe,
111 struct analog_parameters *params)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800112{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300113 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300114 char* mode;
115
Michael Krufkyc7919d52007-12-08 17:06:30 -0300116 if (params->std & V4L2_STD_MN) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300117 priv->tda8290_easy_mode = 0x01;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300118 mode = "MN";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300119 } else if (params->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300120 priv->tda8290_easy_mode = 0x02;
121 mode = "B";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300122 } else if (params->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300123 priv->tda8290_easy_mode = 0x04;
124 mode = "GH";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300125 } else if (params->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300126 priv->tda8290_easy_mode = 0x08;
127 mode = "I";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300128 } else if (params->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300129 priv->tda8290_easy_mode = 0x10;
130 mode = "DK";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300131 } else if (params->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300132 priv->tda8290_easy_mode = 0x20;
133 mode = "L";
Michael Krufkyc7919d52007-12-08 17:06:30 -0300134 } else if (params->std & V4L2_STD_SECAM_LC) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300135 priv->tda8290_easy_mode = 0x40;
136 mode = "LC";
137 } else {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300138 priv->tda8290_easy_mode = 0x10;
139 mode = "xx";
140 }
141
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300142 tuner_dbg("setting tda829x to system %s\n", mode);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300143}
144
Michael Krufkyc7919d52007-12-08 17:06:30 -0300145static void tda8290_set_params(struct dvb_frontend *fe,
146 struct analog_parameters *params)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300147{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300148 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300149
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800150 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300151 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800152 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200153 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800154 unsigned char gainset_off[] = { 0x28, 0x14 };
155 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
156 unsigned char adc_head_6[] = { 0x05, 0x04 };
157 unsigned char adc_head_9[] = { 0x05, 0x02 };
158 unsigned char adc_head_12[] = { 0x05, 0x01 };
159 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
160 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
161 unsigned char gainset_2[] = { 0x28, 0x64 };
162 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
163 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
164 unsigned char if_agc_set[] = { 0x0f, 0x81 };
165 unsigned char addr_adc_sat = 0x1a;
166 unsigned char addr_agc_stat = 0x1d;
167 unsigned char addr_pll_stat = 0x1b;
168 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800169 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300170 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800171
Michael Krufkyc7919d52007-12-08 17:06:30 -0300172 set_audio(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300173
Michael Krufkyab166052007-12-09 02:26:48 -0300174 if (priv->cfg.config)
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300175 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300176 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
177 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
178 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800179 msleep(1);
180
Michael Krufkyb2083192007-05-29 22:54:06 -0300181 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300182 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
183 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
184 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300185 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300186 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800187 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300188 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
189 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800190
Michael Krufky4e9154b2007-10-21 19:39:50 -0300191 tda8290_i2c_bridge(fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300192
Michael Krufky4e9154b2007-10-21 19:39:50 -0300193 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300194 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky746d97322007-08-25 19:08:45 -0300195
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300196 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300197 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
198 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300199 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300200 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
201 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
202 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
203 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300204 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
205 break;
206 } else {
207 tuner_dbg("tda8290 not locked, no signal?\n");
208 msleep(100);
209 }
210 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800211 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800212 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
213 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
214 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300215 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800216 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300217 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
218 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
219 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
220 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800221 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800222 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
223 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300224 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300225 priv->cfg.agcf(fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800226 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300227 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
228 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
229 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
230 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800231 if((agc_stat > 115) || !(pll_stat & 0x80)) {
232 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300233 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
234 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800235 msleep(100);
236 }
237 }
238 }
239
240 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300241 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300242 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
243 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
244 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
245 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800246 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800247 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300248 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800249 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300250 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800251 }
252 }
253
Michael Krufky4e9154b2007-10-21 19:39:50 -0300254 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300255 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800256}
257
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800258/*---------------------------------------------------------------------*/
259
Michael Krufky4e9154b2007-10-21 19:39:50 -0300260static void tda8295_power(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300261{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300262 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300263 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
264
265 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
266 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
267
268 if (enable)
269 buf[1] = 0x01;
270 else
271 buf[1] = 0x03;
272
273 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
274}
275
Michael Krufky4e9154b2007-10-21 19:39:50 -0300276static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300277{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300278 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300279 unsigned char buf[] = { 0x01, 0x00 };
280
281 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
282 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
283
284 if (enable)
285 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
286 else
287 buf[1] = 0x00; /* reset active bit */
288
289 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
290}
291
Michael Krufky4e9154b2007-10-21 19:39:50 -0300292static void tda8295_set_video_std(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300293{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300294 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300295 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
296
297 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
298
Michael Krufky4e9154b2007-10-21 19:39:50 -0300299 tda8295_set_easy_mode(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300300 msleep(20);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300301 tda8295_set_easy_mode(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300302}
303
304/*---------------------------------------------------------------------*/
305
Michael Krufky4e9154b2007-10-21 19:39:50 -0300306static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300307{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300308 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300309 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
310
311 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
312 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
313
314 if (enable)
315 buf[1] &= ~0x40;
316 else
317 buf[1] |= 0x40;
318
319 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
320}
321
Michael Krufky4e9154b2007-10-21 19:39:50 -0300322static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300323{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300324 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300325 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
326 unsigned char set_gpio_val[] = { 0x46, 0x00 };
327
328 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
329 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
330 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
331 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
332
333 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
334
335 if (enable) {
336 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
337 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
338 }
339 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
340 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
341}
342
Michael Krufky4e9154b2007-10-21 19:39:50 -0300343static int tda8295_has_signal(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300344{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300345 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300346
347 unsigned char hvpll_stat = 0x26;
348 unsigned char ret;
349
350 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
351 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
352 return (ret & 0x01) ? 65535 : 0;
353}
354
355/*---------------------------------------------------------------------*/
356
Michael Krufkyc7919d52007-12-08 17:06:30 -0300357static void tda8295_set_params(struct dvb_frontend *fe,
358 struct analog_parameters *params)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300359{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300360 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300361
362 unsigned char blanking_mode[] = { 0x1d, 0x00 };
363
Michael Krufkyc7919d52007-12-08 17:06:30 -0300364 set_audio(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300365
Harvey Harrison7e28adb2008-04-08 23:20:00 -0300366 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300367
Michael Krufky4e9154b2007-10-21 19:39:50 -0300368 tda8295_power(fe, 1);
369 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300370
371 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
372 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
373
Michael Krufky4e9154b2007-10-21 19:39:50 -0300374 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300375
376 blanking_mode[1] = 0x03;
377 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
378 msleep(20);
379
Michael Krufky4e9154b2007-10-21 19:39:50 -0300380 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300381
Michael Krufky4e9154b2007-10-21 19:39:50 -0300382 if (fe->ops.tuner_ops.set_analog_params)
Michael Krufkyc7919d52007-12-08 17:06:30 -0300383 fe->ops.tuner_ops.set_analog_params(fe, params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300384
385 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300386 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300387
Michael Krufky4e9154b2007-10-21 19:39:50 -0300388 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300389 tuner_dbg("tda8295 is locked\n");
390 else
391 tuner_dbg("tda8295 not locked, no signal?\n");
392
Michael Krufky4e9154b2007-10-21 19:39:50 -0300393 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300394}
395
396/*---------------------------------------------------------------------*/
397
Michael Krufky4e9154b2007-10-21 19:39:50 -0300398static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300400 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 unsigned char i2c_get_afc[1] = { 0x1B };
403 unsigned char afc = 0;
404
Michael Krufkydb8a6952007-08-21 01:24:42 -0300405 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
406 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300407 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300408}
409
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800410/*---------------------------------------------------------------------*/
411
Michael Krufky4e9154b2007-10-21 19:39:50 -0300412static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700413{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300414 struct tda8290_priv *priv = fe->analog_demod_priv;
415
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800416 unsigned char cb1[] = { 0x30, 0xD0 };
417 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200418 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300419 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800420
Michael Krufky4e9154b2007-10-21 19:39:50 -0300421 tda8290_i2c_bridge(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300422 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800423 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300424 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300425 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300426 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
427 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700428}
429
Michael Krufky4e9154b2007-10-21 19:39:50 -0300430static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300431{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300432 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300433
Michael Krufky4e9154b2007-10-21 19:39:50 -0300434 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300435}
436
Michael Krufky4e9154b2007-10-21 19:39:50 -0300437static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800438{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300439 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300440
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800441 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300442 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800443 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
444
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300445 if ((priv->cfg.config == 1) || (priv->cfg.config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300446 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300447 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300448 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
449 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800450}
451
Michael Krufky4e9154b2007-10-21 19:39:50 -0300452static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300453{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300454 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300455
456 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
457 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
458 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
459 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
460 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
461 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
462 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
463
Michael Krufky4e9154b2007-10-21 19:39:50 -0300464 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300465
Michael Krufky4e9154b2007-10-21 19:39:50 -0300466 tda8295_set_easy_mode(fe, 0);
467 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300468
469 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
470 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
471 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
472 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
473 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
476
Michael Krufky4e9154b2007-10-21 19:39:50 -0300477 tda8295_agc1_out(fe, 0);
478 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300479}
480
Michael Krufky4e9154b2007-10-21 19:39:50 -0300481static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800482{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300483 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800484 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800485 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800486 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800487 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300488 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800489 .buf=tda8275_init, .len = 14};
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300490 if (priv->ver & TDA8275A)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800491 msg.buf = tda8275a_init;
492
Michael Krufky4e9154b2007-10-21 19:39:50 -0300493 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300494 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300495 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800496}
497
498/*---------------------------------------------------------------------*/
499
Michael Krufky4e9154b2007-10-21 19:39:50 -0300500static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300501{
Michael Krufkya4f263b2008-01-06 15:52:56 -0300502 struct tda8290_priv *priv = fe->analog_demod_priv;
503
Michael Krufky006ed1e2008-01-09 10:44:27 -0300504 /* only try to release the tuner if we've
505 * attached it from within this module */
506 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
Michael Krufkya4f263b2008-01-06 15:52:56 -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 Krufkyf21e0d72008-01-02 03:01:54 -0300514static struct tda18271_config tda829x_tda18271_config = {
515 .gate = TDA18271_GATE_ANALOG,
516};
517
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300518static int tda829x_find_tuner(struct dvb_frontend *fe)
519{
520 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300521 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300522 int i, ret, tuners_found;
523 u32 tuner_addrs;
524 u8 data;
525 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
526
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300527 if (NULL == analog_ops->i2c_gate_ctrl)
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300528 return -EINVAL;
529
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300530 analog_ops->i2c_gate_ctrl(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300531
532 /* probe for tuner chip */
533 tuners_found = 0;
534 tuner_addrs = 0;
535 for (i = 0x60; i <= 0x63; i++) {
536 msg.addr = i;
537 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
538 if (ret == 1) {
539 tuners_found++;
540 tuner_addrs = (tuner_addrs << 8) + i;
541 }
542 }
543 /* if there is more than one tuner, we expect the right one is
544 behind the bridge and we choose the highest address that doesn't
545 give a response now
546 */
547
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300548 analog_ops->i2c_gate_ctrl(fe, 0);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300549
550 if (tuners_found > 1)
551 for (i = 0; i < tuners_found; i++) {
552 msg.addr = tuner_addrs & 0xff;
553 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
554 if (ret == 1)
555 tuner_addrs = tuner_addrs >> 8;
556 else
557 break;
558 }
559
560 if (tuner_addrs == 0) {
561 tuner_addrs = 0x60;
562 tuner_info("could not clearly identify tuner address, "
563 "defaulting to %x\n", tuner_addrs);
564 } else {
565 tuner_addrs = tuner_addrs & 0xff;
566 tuner_info("setting tuner address to %x\n", tuner_addrs);
567 }
568 priv->tda827x_addr = tuner_addrs;
569 msg.addr = tuner_addrs;
570
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300571 analog_ops->i2c_gate_ctrl(fe, 1);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300572 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
573
574 if (ret != 1) {
575 tuner_warn("tuner access failed!\n");
576 return -EREMOTEIO;
577 }
578
Michael Krufky255b5112008-01-01 22:52:09 -0300579 if ((data == 0x83) || (data == 0x84)) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300580 priv->ver |= TDA18271;
Michael Krufky68816472007-12-08 16:25:41 -0300581 tda18271_attach(fe, priv->tda827x_addr,
Michael Krufkye435f952007-12-09 22:23:30 -0300582 priv->i2c_props.adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300583 &tda829x_tda18271_config);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300584 } else {
585 if ((data & 0x3c) == 0)
586 priv->ver |= TDA8275;
587 else
588 priv->ver |= TDA8275A;
589
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300590 tda827x_attach(fe, priv->tda827x_addr, priv->i2c_props.adap, &priv->cfg);
591 priv->cfg.switch_addr = priv->i2c_props.addr;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300592 }
Michael Krufky68816472007-12-08 16:25:41 -0300593 if (fe->ops.tuner_ops.init)
594 fe->ops.tuner_ops.init(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300595
Michael Krufky68816472007-12-08 16:25:41 -0300596 if (fe->ops.tuner_ops.sleep)
597 fe->ops.tuner_ops.sleep(fe);
Michael Krufky63c25482007-11-23 15:08:11 -0300598
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300599 analog_ops->i2c_gate_ctrl(fe, 0);
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300600
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300601 return 0;
602}
603
Michael Krufkyf1f32842007-11-03 22:14:54 -0300604static int tda8290_probe(struct tuner_i2c_props *i2c_props)
605{
606#define TDA8290_ID 0x89
607 unsigned char tda8290_id[] = { 0x1f, 0x00 };
608
609 /* detect tda8290 */
610 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
611 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
612
613 if (tda8290_id[1] == TDA8290_ID) {
Michael Krufkyab166052007-12-09 02:26:48 -0300614 if (debug)
Michael Krufkyf1f32842007-11-03 22:14:54 -0300615 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
Harvey Harrison7e28adb2008-04-08 23:20:00 -0300616 __func__, i2c_adapter_id(i2c_props->adap),
Michael Krufkyf1f32842007-11-03 22:14:54 -0300617 i2c_props->addr);
618 return 0;
619 }
620
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300621 return -ENODEV;
Michael Krufkyf1f32842007-11-03 22:14:54 -0300622}
623
624static int tda8295_probe(struct tuner_i2c_props *i2c_props)
625{
626#define TDA8295_ID 0x8a
627 unsigned char tda8295_id[] = { 0x2f, 0x00 };
628
629 /* detect tda8295 */
630 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
631 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
632
633 if (tda8295_id[1] == TDA8295_ID) {
Michael Krufkyab166052007-12-09 02:26:48 -0300634 if (debug)
Michael Krufkyf1f32842007-11-03 22:14:54 -0300635 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
Harvey Harrison7e28adb2008-04-08 23:20:00 -0300636 __func__, i2c_adapter_id(i2c_props->adap),
Michael Krufkyf1f32842007-11-03 22:14:54 -0300637 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
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300644static struct analog_demod_ops tda8290_ops = {
Michael Krufkyc7919d52007-12-08 17:06:30 -0300645 .set_params = tda8290_set_params,
Michael Krufky746d97322007-08-25 19:08:45 -0300646 .has_signal = tda8290_has_signal,
647 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300648 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300649 .i2c_gate_ctrl = tda8290_i2c_bridge,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300650};
651
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300652static struct analog_demod_ops tda8295_ops = {
Michael Krufkyc7919d52007-12-08 17:06:30 -0300653 .set_params = tda8295_set_params,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300654 .has_signal = tda8295_has_signal,
655 .standby = tda8295_standby,
656 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300657 .i2c_gate_ctrl = tda8295_i2c_bridge,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300658};
659
Michael Krufkyab166052007-12-09 02:26:48 -0300660struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
661 struct i2c_adapter *i2c_adap, u8 i2c_addr,
662 struct tda829x_config *cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Michael Krufkyb2083192007-05-29 22:54:06 -0300664 struct tda8290_priv *priv = NULL;
Michael Krufkyab166052007-12-09 02:26:48 -0300665 char *name;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300666
Michael Krufkyb2083192007-05-29 22:54:06 -0300667 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
668 if (priv == NULL)
Michael Krufkyab166052007-12-09 02:26:48 -0300669 return NULL;
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300670 fe->analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300671
Michael Krufkyab166052007-12-09 02:26:48 -0300672 priv->i2c_props.addr = i2c_addr;
673 priv->i2c_props.adap = i2c_adap;
Michael Krufky27566652008-04-22 14:41:53 -0300674 priv->i2c_props.name = "tda829x";
Michael Krufkyab166052007-12-09 02:26:48 -0300675 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;
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300682 memcpy(&fe->ops.analog_ops, &tda8290_ops,
683 sizeof(struct analog_demod_ops));
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800684 }
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300685
Michael Krufkyf1f32842007-11-03 22:14:54 -0300686 if (tda8295_probe(&priv->i2c_props) == 0) {
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300687 priv->ver = TDA8295;
Michael Krufkybc3e5c72007-12-21 11:18:32 -0300688 memcpy(&fe->ops.analog_ops, &tda8295_ops,
689 sizeof(struct analog_demod_ops));
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800690 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800691
Michael Krufkyc9076272007-12-24 04:36:14 -0300692 if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
693 (tda829x_find_tuner(fe) < 0))
Michael Krufkyfa746aee2007-12-09 05:16:10 -0300694 goto fail;
Michael Krufky746d97322007-08-25 19:08:45 -0300695
Michael Krufkyab166052007-12-09 02:26:48 -0300696 switch (priv->ver) {
Michael Krufkyc9076272007-12-24 04:36:14 -0300697 case TDA8290:
698 name = "tda8290";
699 break;
700 case TDA8295:
701 name = "tda8295";
702 break;
Michael Krufkyab166052007-12-09 02:26:48 -0300703 case TDA8290 | TDA8275:
704 name = "tda8290+75";
705 break;
706 case TDA8295 | TDA8275:
707 name = "tda8295+75";
708 break;
709 case TDA8290 | TDA8275A:
710 name = "tda8290+75a";
711 break;
712 case TDA8295 | TDA8275A:
713 name = "tda8295+75a";
714 break;
715 case TDA8290 | TDA18271:
716 name = "tda8290+18271";
717 break;
718 case TDA8295 | TDA18271:
719 name = "tda8295+18271";
720 break;
721 default:
722 goto fail;
723 }
724 tuner_info("type set to %s\n", name);
725
Michael Krufky0f2ce982008-01-21 10:55:37 -0300726 fe->ops.analog_ops.info.name = name;
727
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300728 if (priv->ver & TDA8290) {
729 tda8290_init_tuner(fe);
730 tda8290_init_if(fe);
731 } else if (priv->ver & TDA8295)
732 tda8295_init_if(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300733
Michael Krufkyab166052007-12-09 02:26:48 -0300734 return fe;
Michael Krufkyfa746aee2007-12-09 05:16:10 -0300735
736fail:
737 tda829x_release(fe);
Michael Krufkyab166052007-12-09 02:26:48 -0300738 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300740EXPORT_SYMBOL_GPL(tda829x_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Michael Krufkyab166052007-12-09 02:26:48 -0300742int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800743{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300744 struct tuner_i2c_props i2c_props = {
Michael Krufkyab166052007-12-09 02:26:48 -0300745 .adap = i2c_adap,
746 .addr = i2c_addr,
Michael Krufky910bb3e2007-08-27 21:22:20 -0300747 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300748
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300749 unsigned char soft_reset[] = { 0x00, 0x00 };
750 unsigned char easy_mode_b[] = { 0x01, 0x02 };
751 unsigned char easy_mode_g[] = { 0x01, 0x04 };
752 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800753 unsigned char addr_dto_lsb = 0x07;
754 unsigned char data;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300755#define PROBE_BUFFER_SIZE 8
756 unsigned char buf[PROBE_BUFFER_SIZE];
757 int i;
758
759 /* rule out tda9887, which would return the same byte repeatedly */
760 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
761 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
762 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
Michael Krufkybbe1e0b2007-11-05 09:54:42 -0300763 if (buf[i] != buf[0])
764 break;
Michael Krufkya818e1c2007-11-04 11:03:22 -0300765 }
766
767 /* all bytes are equal, not a tda829x - probably a tda9887 */
768 if (i == PROBE_BUFFER_SIZE)
769 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800770
Michael Krufkyf1f32842007-11-03 22:14:54 -0300771 if ((tda8290_probe(&i2c_props) == 0) ||
772 (tda8295_probe(&i2c_props) == 0))
773 return 0;
774
775 /* fall back to old probing method */
Michael Krufky910bb3e2007-08-27 21:22:20 -0300776 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
777 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
778 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
779 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800780 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300781 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
782 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
783 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
784 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800785 if (data == 0x7b) {
786 return 0;
787 }
788 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300789 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Michael Krufky1f3a4e322007-11-04 10:51:28 -0300790 return -ENODEV;
Hartmut Hackmann95736032005-11-08 21:38:00 -0800791}
Michael Krufkyf1f32842007-11-03 22:14:54 -0300792EXPORT_SYMBOL_GPL(tda829x_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300793
Michael Krufky8c125f2c2007-10-27 02:00:57 -0300794MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300795MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300796MODULE_LICENSE("GPL");
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798/*
799 * Overrides for Emacs so that we follow Linus's tabbing style.
800 * ---------------------------------------------------------------------------
801 * Local variables:
802 * c-basic-offset: 8
803 * End:
804 */