blob: 5975c548b8a6e61580db6035a445ed8ac2ba7d7b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -08002
3 i2c tv tuner chip device driver
4 controls the philips tda8290+75 tuner chip combo.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Michael Krufky910bb3e2007-08-27 21:22:20 -030019
20 This "tda8290" module was split apart from the original "tuner" module.
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080021*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/delay.h>
Michael Krufkyffbb8072007-08-21 01:14:12 -030025#include <linux/videodev.h>
Michael Krufky910bb3e2007-08-27 21:22:20 -030026#include "tda8290.h"
Michael Krufky746d97322007-08-25 19:08:45 -030027#include "tda827x.h"
Michael Krufky5bea1cd2007-10-22 09:56:38 -030028#include "tda18271.h"
Michael Krufky910bb3e2007-08-27 21:22:20 -030029
Michael Krufky5bea1cd2007-10-22 09:56:38 -030030static int tuner_debug;
Michael Krufky746d97322007-08-25 19:08:45 -030031module_param_named(debug, tuner_debug, int, 0644);
Michael Krufky910bb3e2007-08-27 21:22:20 -030032MODULE_PARM_DESC(debug, "enable verbose debug messages");
33
34#define PREFIX "tda8290 "
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/* ---------------------------------------------------------------------- */
37
Michael Krufkyb2083192007-05-29 22:54:06 -030038struct tda8290_priv {
Michael Krufkydb8a6952007-08-21 01:24:42 -030039 struct tuner_i2c_props i2c_props;
40
Michael Krufkyb2083192007-05-29 22:54:06 -030041 unsigned char tda8290_easy_mode;
Michael Krufky746d97322007-08-25 19:08:45 -030042
Michael Krufkyb2083192007-05-29 22:54:06 -030043 unsigned char tda827x_addr;
44 unsigned char tda827x_ver;
Michael Krufky910bb3e2007-08-27 21:22:20 -030045
Michael Krufky746d97322007-08-25 19:08:45 -030046 struct tda827x_config cfg;
Michael Krufky4e9154b2007-10-21 19:39:50 -030047
48 struct tuner *t;
Michael Krufkyb2083192007-05-29 22:54:06 -030049};
50
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080051/*---------------------------------------------------------------------*/
52
Michael Krufkya72dd302007-10-24 09:30:17 -030053static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080054{
Michael Krufky4e9154b2007-10-21 19:39:50 -030055 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -030056
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080057 unsigned char enable[2] = { 0x21, 0xC0 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -020058 unsigned char disable[2] = { 0x21, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080059 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030060
61 if (close) {
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080062 msg = enable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030063 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080064 /* let the bridge stabilize */
65 msleep(20);
66 } else {
67 msg = disable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030068 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080069 }
Michael Krufkya72dd302007-10-24 09:30:17 -030070
71 return 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080072}
73
Michael Krufkya72dd302007-10-24 09:30:17 -030074static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
Michael Krufky5bea1cd2007-10-22 09:56:38 -030075{
Michael Krufky4e9154b2007-10-21 19:39:50 -030076 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -030077
78 unsigned char enable[2] = { 0x45, 0xc1 };
79 unsigned char disable[2] = { 0x46, 0x00 };
80 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
81 unsigned char *msg;
Michael Krufkya72dd302007-10-24 09:30:17 -030082
Michael Krufky5bea1cd2007-10-22 09:56:38 -030083 if (close) {
84 msg = enable;
85 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
86 /* let the bridge stabilize */
87 msleep(20);
88 } else {
89 msg = disable;
90 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
91 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
92
93 buf[2] = msg[1];
94 buf[2] &= ~0x04;
95 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
96 msleep(5);
97
98 msg[1] |= 0x04;
99 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
100 }
Michael Krufkya72dd302007-10-24 09:30:17 -0300101
102 return 0;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300103}
104
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800105/*---------------------------------------------------------------------*/
106
Michael Krufky4e9154b2007-10-21 19:39:50 -0300107static void set_audio(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800108{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300109 struct tda8290_priv *priv = fe->analog_demod_priv;
110 struct tuner *t = priv->t;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300111 char* mode;
112
Michael Krufky746d97322007-08-25 19:08:45 -0300113 if (t->std & V4L2_STD_MN) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300114 priv->tda8290_easy_mode = 0x01;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300115 mode = "MN";
Michael Krufky746d97322007-08-25 19:08:45 -0300116 } else if (t->std & V4L2_STD_B) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300117 priv->tda8290_easy_mode = 0x02;
118 mode = "B";
Michael Krufky746d97322007-08-25 19:08:45 -0300119 } else if (t->std & V4L2_STD_GH) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300120 priv->tda8290_easy_mode = 0x04;
121 mode = "GH";
Michael Krufky746d97322007-08-25 19:08:45 -0300122 } else if (t->std & V4L2_STD_PAL_I) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300123 priv->tda8290_easy_mode = 0x08;
124 mode = "I";
Michael Krufky746d97322007-08-25 19:08:45 -0300125 } else if (t->std & V4L2_STD_DK) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300126 priv->tda8290_easy_mode = 0x10;
127 mode = "DK";
Michael Krufky746d97322007-08-25 19:08:45 -0300128 } else if (t->std & V4L2_STD_SECAM_L) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300129 priv->tda8290_easy_mode = 0x20;
130 mode = "L";
Michael Krufky746d97322007-08-25 19:08:45 -0300131 } else if (t->std & V4L2_STD_SECAM_LC) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300132 priv->tda8290_easy_mode = 0x40;
133 mode = "LC";
134 } else {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300135 priv->tda8290_easy_mode = 0x10;
136 mode = "xx";
137 }
138
Michael Krufky910bb3e2007-08-27 21:22:20 -0300139 tuner_dbg("setting tda8290 to system %s\n", mode);
140}
141
Michael Krufky4e9154b2007-10-21 19:39:50 -0300142static void tda8290_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300143{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300144 struct tda8290_priv *priv = fe->analog_demod_priv;
145 struct tuner *t = priv->t;
146
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800147 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300148 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800149 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200150 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800151 unsigned char gainset_off[] = { 0x28, 0x14 };
152 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
153 unsigned char adc_head_6[] = { 0x05, 0x04 };
154 unsigned char adc_head_9[] = { 0x05, 0x02 };
155 unsigned char adc_head_12[] = { 0x05, 0x01 };
156 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
157 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
158 unsigned char gainset_2[] = { 0x28, 0x64 };
159 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
160 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
161 unsigned char if_agc_set[] = { 0x0f, 0x81 };
162 unsigned char addr_adc_sat = 0x1a;
163 unsigned char addr_agc_stat = 0x1d;
164 unsigned char addr_pll_stat = 0x1b;
165 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800166 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300167 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800168
Michael Krufky746d97322007-08-25 19:08:45 -0300169 struct analog_parameters params = {
170 .frequency = freq,
171 .mode = t->mode,
172 .audmode = t->audmode,
173 .std = t->std
174 };
Michael Krufky910bb3e2007-08-27 21:22:20 -0300175
Michael Krufky4e9154b2007-10-21 19:39:50 -0300176 set_audio(fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300177
178 tuner_dbg("tda827xa config is 0x%02x\n", t->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)
197 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 Krufky4e9154b2007-10-21 19:39:50 -0300360static void tda8295_set_freq(struct dvb_frontend *fe, unsigned int freq)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300361{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300362 struct tda8290_priv *priv = fe->analog_demod_priv;
363 struct tuner *t = priv->t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300364
365 unsigned char blanking_mode[] = { 0x1d, 0x00 };
366
367 struct analog_parameters params = {
368 .frequency = freq,
369 .mode = t->mode,
370 .audmode = t->audmode,
371 .std = t->std
372 };
373
Michael Krufky4e9154b2007-10-21 19:39:50 -0300374 set_audio(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300375
Michael Krufky5c82f442007-10-22 01:10:39 -0300376 tuner_dbg("%s: freq = %d\n", __FUNCTION__, freq);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300377
Michael Krufky4e9154b2007-10-21 19:39:50 -0300378 tda8295_power(fe, 1);
379 tda8295_agc1_out(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300380
381 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
382 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
383
Michael Krufky4e9154b2007-10-21 19:39:50 -0300384 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300385
386 blanking_mode[1] = 0x03;
387 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
388 msleep(20);
389
Michael Krufky4e9154b2007-10-21 19:39:50 -0300390 tda8295_i2c_bridge(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300391
Michael Krufky4e9154b2007-10-21 19:39:50 -0300392 if (fe->ops.tuner_ops.set_analog_params)
393 fe->ops.tuner_ops.set_analog_params(fe, &params);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300394
395 if (priv->cfg.agcf)
Michael Krufky4e9154b2007-10-21 19:39:50 -0300396 priv->cfg.agcf(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300397
Michael Krufky4e9154b2007-10-21 19:39:50 -0300398 if (tda8295_has_signal(fe))
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300399 tuner_dbg("tda8295 is locked\n");
400 else
401 tuner_dbg("tda8295 not locked, no signal?\n");
402
Michael Krufky4e9154b2007-10-21 19:39:50 -0300403 tda8295_i2c_bridge(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300404}
405
406/*---------------------------------------------------------------------*/
407
Michael Krufky4e9154b2007-10-21 19:39:50 -0300408static int tda8290_has_signal(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300410 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 unsigned char i2c_get_afc[1] = { 0x1B };
413 unsigned char afc = 0;
414
Michael Krufkydb8a6952007-08-21 01:24:42 -0300415 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
416 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300417 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300418}
419
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800420/*---------------------------------------------------------------------*/
421
Michael Krufky4e9154b2007-10-21 19:39:50 -0300422static void tda8290_standby(struct dvb_frontend *fe)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700423{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300424 struct tda8290_priv *priv = fe->analog_demod_priv;
425
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800426 unsigned char cb1[] = { 0x30, 0xD0 };
427 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200428 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300429 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800430
Michael Krufky4e9154b2007-10-21 19:39:50 -0300431 tda8290_i2c_bridge(fe, 1);
Michael Krufkyb2083192007-05-29 22:54:06 -0300432 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800433 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300434 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300435 tda8290_i2c_bridge(fe, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300436 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
437 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700438}
439
Michael Krufky4e9154b2007-10-21 19:39:50 -0300440static void tda8295_standby(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300441{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300442 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300443
Michael Krufky4e9154b2007-10-21 19:39:50 -0300444 tda8295_power(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300445}
446
Michael Krufky4e9154b2007-10-21 19:39:50 -0300447static void tda8290_init_if(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800448{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300449 struct tda8290_priv *priv = fe->analog_demod_priv;
450 struct tuner *t = priv->t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300451
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800452 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300453 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800454 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
455
Michael Krufky746d97322007-08-25 19:08:45 -0300456 if ((t->config == 1) || (t->config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300457 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300458 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300459 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
460 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800461}
462
Michael Krufky4e9154b2007-10-21 19:39:50 -0300463static void tda8295_init_if(struct dvb_frontend *fe)
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300464{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300465 struct tda8290_priv *priv = fe->analog_demod_priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300466
467 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
468 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
469 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
470 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
471 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
472 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
473 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
474
Michael Krufky4e9154b2007-10-21 19:39:50 -0300475 tda8295_power(fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300476
Michael Krufky4e9154b2007-10-21 19:39:50 -0300477 tda8295_set_easy_mode(fe, 0);
478 tda8295_set_video_std(fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300479
480 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
481 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
482 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
483 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
484 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
485 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
486 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
487
Michael Krufky4e9154b2007-10-21 19:39:50 -0300488 tda8295_agc1_out(fe, 0);
489 tda8295_agc2_out(fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300490}
491
Michael Krufky4e9154b2007-10-21 19:39:50 -0300492static void tda8290_init_tuner(struct dvb_frontend *fe)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800493{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300494 struct tda8290_priv *priv = fe->analog_demod_priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800495 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800496 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800497 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800498 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300499 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800500 .buf=tda8275_init, .len = 14};
Michael Krufkyb2083192007-05-29 22:54:06 -0300501 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800502 msg.buf = tda8275a_init;
503
Michael Krufky4e9154b2007-10-21 19:39:50 -0300504 tda8290_i2c_bridge(fe, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300505 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300506 tda8290_i2c_bridge(fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800507}
508
509/*---------------------------------------------------------------------*/
510
Michael Krufky4e9154b2007-10-21 19:39:50 -0300511static void tda829x_release(struct dvb_frontend *fe)
Michael Krufky024cf532007-06-04 15:20:11 -0300512{
Michael Krufky4e9154b2007-10-21 19:39:50 -0300513 if (fe->ops.tuner_ops.release)
514 fe->ops.tuner_ops.release(fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300515
Michael Krufky4e9154b2007-10-21 19:39:50 -0300516 kfree(fe->analog_demod_priv);
517 fe->analog_demod_priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300518}
519
Michael Krufky1dde7a42007-10-21 13:40:56 -0300520static struct analog_tuner_ops tda8290_tuner_ops = {
Michael Krufky746d97322007-08-25 19:08:45 -0300521 .set_tv_freq = tda8290_set_freq,
522 .set_radio_freq = tda8290_set_freq,
523 .has_signal = tda8290_has_signal,
524 .standby = tda8290_standby,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300525 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300526 .i2c_gate_ctrl = tda8290_i2c_bridge,
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300527};
528
Michael Krufky1dde7a42007-10-21 13:40:56 -0300529static struct analog_tuner_ops tda8295_tuner_ops = {
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300530 .set_tv_freq = tda8295_set_freq,
531 .set_radio_freq = tda8295_set_freq,
532 .has_signal = tda8295_has_signal,
533 .standby = tda8295_standby,
534 .release = tda829x_release,
Michael Krufkya72dd302007-10-24 09:30:17 -0300535 .i2c_gate_ctrl = tda8295_i2c_bridge,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300536};
537
Michael Krufky746d97322007-08-25 19:08:45 -0300538int tda8290_attach(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
Michael Krufkyb2083192007-05-29 22:54:06 -0300540 struct tda8290_priv *priv = NULL;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800541 u8 data;
542 int i, ret, tuners_found;
543 u32 tuner_addrs;
544 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Michael Krufkyb2083192007-05-29 22:54:06 -0300546 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
547 if (priv == NULL)
Michael Krufky746d97322007-08-25 19:08:45 -0300548 return -ENOMEM;
Michael Krufky16f29162007-10-21 15:22:25 -0300549 t->fe.analog_demod_priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300550
Michael Krufky746d97322007-08-25 19:08:45 -0300551 priv->i2c_props.addr = t->i2c.addr;
552 priv->i2c_props.adap = t->i2c.adapter;
553 priv->cfg.config = &t->config;
554 priv->cfg.tuner_callback = t->tuner_callback;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300555 priv->t = t;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300556
Michael Krufky4e9154b2007-10-21 19:39:50 -0300557 tda8290_i2c_bridge(&t->fe, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800558 /* probe for tuner chip */
559 tuners_found = 0;
560 tuner_addrs = 0;
561 for (i=0x60; i<= 0x63; i++) {
562 msg.addr = i;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300563 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800564 if (ret == 1) {
565 tuners_found++;
566 tuner_addrs = (tuner_addrs << 8) + i;
567 }
568 }
569 /* if there is more than one tuner, we expect the right one is
570 behind the bridge and we choose the highest address that doesn't
571 give a response now
572 */
Michael Krufky4e9154b2007-10-21 19:39:50 -0300573 tda8290_i2c_bridge(&t->fe, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800574 if(tuners_found > 1)
575 for (i = 0; i < tuners_found; i++) {
576 msg.addr = tuner_addrs & 0xff;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300577 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800578 if(ret == 1)
579 tuner_addrs = tuner_addrs >> 8;
580 else
581 break;
582 }
583 if (tuner_addrs == 0) {
584 tuner_addrs = 0x61;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300585 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
Nickolay V. Shmyrev01cb9632005-11-08 21:38:00 -0800586 tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800587 } else {
588 tuner_addrs = tuner_addrs & 0xff;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300589 tuner_info("setting tuner address to %x\n", tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800590 }
Michael Krufkyb2083192007-05-29 22:54:06 -0300591 priv->tda827x_addr = tuner_addrs;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800592 msg.addr = tuner_addrs;
593
Michael Krufky4e9154b2007-10-21 19:39:50 -0300594 tda8290_i2c_bridge(&t->fe, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300595
Michael Krufkydb8a6952007-08-21 01:24:42 -0300596 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800597 if( ret != 1)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300598 tuner_warn("TDA827x access failed!\n");
599
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800600 if ((data & 0x3c) == 0) {
Michael Krufky746d97322007-08-25 19:08:45 -0300601 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300602 priv->tda827x_ver = 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800603 } else {
Michael Krufky746d97322007-08-25 19:08:45 -0300604 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300605 priv->tda827x_ver = 2;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800606 }
Michael Krufky746d97322007-08-25 19:08:45 -0300607 tda827x_attach(&t->fe, priv->tda827x_addr,
608 priv->i2c_props.adap, &priv->cfg);
Michael Krufky7fd8b262007-06-06 16:15:15 -0300609
Michael Krufky746d97322007-08-25 19:08:45 -0300610 /* FIXME: tda827x module doesn't probe the tuner until
611 * tda827x_initial_sleep is called
612 */
613 if (t->fe.ops.tuner_ops.sleep)
614 t->fe.ops.tuner_ops.sleep(&t->fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Michael Krufky1dde7a42007-10-21 13:40:56 -0300616 t->fe.ops.analog_demod_ops = &tda8290_tuner_ops;
Michael Krufky746d97322007-08-25 19:08:45 -0300617
618 tuner_info("type set to %s\n", t->i2c.name);
619
Michael Krufky746d97322007-08-25 19:08:45 -0300620 t->mode = V4L2_TUNER_ANALOG_TV;
621
Michael Krufky4e9154b2007-10-21 19:39:50 -0300622 tda8290_init_tuner(&t->fe);
623 tda8290_init_if(&t->fe);
Michael Krufky746d97322007-08-25 19:08:45 -0300624 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300626EXPORT_SYMBOL_GPL(tda8290_attach);
627
628int tda8295_attach(struct tuner *t)
629{
630 struct tda8290_priv *priv = NULL;
631 u8 data;
632 int i, ret, tuners_found;
633 u32 tuner_addrs;
634 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
635
636 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
637 if (priv == NULL)
638 return -ENOMEM;
Michael Krufky16f29162007-10-21 15:22:25 -0300639 t->fe.analog_demod_priv = priv;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300640
641 priv->i2c_props.addr = t->i2c.addr;
642 priv->i2c_props.adap = t->i2c.adapter;
Michael Krufky4e9154b2007-10-21 19:39:50 -0300643 priv->t = t;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300644
Michael Krufky4e9154b2007-10-21 19:39:50 -0300645 tda8295_i2c_bridge(&t->fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300646 /* probe for tuner chip */
647 tuners_found = 0;
648 tuner_addrs = 0;
649 for (i = 0x60; i <= 0x63; i++) {
650 msg.addr = i;
651 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
652 if (ret == 1) {
653 tuners_found++;
654 tuner_addrs = (tuner_addrs << 8) + i;
655 }
656 }
657 /* if there is more than one tuner, we expect the right one is
658 behind the bridge and we choose the highest address that doesn't
659 give a response now
660 */
Michael Krufky4e9154b2007-10-21 19:39:50 -0300661 tda8295_i2c_bridge(&t->fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300662 if (tuners_found > 1)
663 for (i = 0; i < tuners_found; i++) {
664 msg.addr = tuner_addrs & 0xff;
665 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
666 if (ret == 1)
667 tuner_addrs = tuner_addrs >> 8;
668 else
669 break;
670 }
671 if (tuner_addrs == 0) {
672 tuner_addrs = 0x60;
673 tuner_info("could not clearly identify tuner address, "
674 "defaulting to %x\n", tuner_addrs);
675 } else {
676 tuner_addrs = tuner_addrs & 0xff;
677 tuner_info("setting tuner address to %x\n", tuner_addrs);
678 }
679 priv->tda827x_addr = tuner_addrs;
680 msg.addr = tuner_addrs;
681
Michael Krufky4e9154b2007-10-21 19:39:50 -0300682 tda8295_i2c_bridge(&t->fe, 1);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300683 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky4e9154b2007-10-21 19:39:50 -0300684 tda8295_i2c_bridge(&t->fe, 0);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300685 if (ret != 1)
686 tuner_warn("TDA827x access failed!\n");
687 if ((data & 0x3c) == 0) {
688 strlcpy(t->i2c.name, "tda8295+18271", sizeof(t->i2c.name));
689 tda18271_attach(&t->fe, priv->tda827x_addr,
690 priv->i2c_props.adap);
691 priv->tda827x_ver = 4;
692 } else {
693 strlcpy(t->i2c.name, "tda8295+75a", sizeof(t->i2c.name));
694 tda827x_attach(&t->fe, priv->tda827x_addr,
695 priv->i2c_props.adap, &priv->cfg);
696
697 /* FIXME: tda827x module doesn't probe the tuner until
698 * tda827x_initial_sleep is called
699 */
700 if (t->fe.ops.tuner_ops.sleep)
701 t->fe.ops.tuner_ops.sleep(&t->fe);
702 priv->tda827x_ver = 2;
703 }
704 priv->tda827x_ver |= 1; /* signifies 8295 vs 8290 */
705 tuner_info("type set to %s\n", t->i2c.name);
706
Michael Krufky1dde7a42007-10-21 13:40:56 -0300707 t->fe.ops.analog_demod_ops = &tda8295_tuner_ops;
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300708
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300709 t->mode = V4L2_TUNER_ANALOG_TV;
710
Michael Krufky4e9154b2007-10-21 19:39:50 -0300711 tda8295_init_if(&t->fe);
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300712 return 0;
713}
714EXPORT_SYMBOL_GPL(tda8295_attach);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Michael Krufky746d97322007-08-25 19:08:45 -0300716int tda8290_probe(struct tuner *t)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800717{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300718 struct tuner_i2c_props i2c_props = {
Michael Krufky746d97322007-08-25 19:08:45 -0300719 .adap = t->i2c.adapter,
720 .addr = t->i2c.addr
Michael Krufky910bb3e2007-08-27 21:22:20 -0300721 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300722
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300723 unsigned char soft_reset[] = { 0x00, 0x00 };
724 unsigned char easy_mode_b[] = { 0x01, 0x02 };
725 unsigned char easy_mode_g[] = { 0x01, 0x04 };
726 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800727 unsigned char addr_dto_lsb = 0x07;
728 unsigned char data;
729
Michael Krufky910bb3e2007-08-27 21:22:20 -0300730 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
731 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
732 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
733 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800734 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300735 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
736 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
737 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
738 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800739 if (data == 0x7b) {
740 return 0;
741 }
742 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300743 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800744 return -1;
745}
Michael Krufky910bb3e2007-08-27 21:22:20 -0300746EXPORT_SYMBOL_GPL(tda8290_probe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300747
748MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
Michael Krufky5bea1cd2007-10-22 09:56:38 -0300749MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
Michael Krufky910bb3e2007-08-27 21:22:20 -0300750MODULE_LICENSE("GPL");
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752/*
753 * Overrides for Emacs so that we follow Linus's tabbing style.
754 * ---------------------------------------------------------------------------
755 * Local variables:
756 * c-basic-offset: 8
757 * End:
758 */