blob: 5d30cbcd7361a55ccee2748aba33228b74ea5d57 [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 Krufky910bb3e2007-08-27 21:22:20 -030028
Michael Krufky746d97322007-08-25 19:08:45 -030029static int tuner_debug = 0;
30module_param_named(debug, tuner_debug, int, 0644);
Michael Krufky910bb3e2007-08-27 21:22:20 -030031MODULE_PARM_DESC(debug, "enable verbose debug messages");
32
33#define PREFIX "tda8290 "
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/* ---------------------------------------------------------------------- */
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;
43 unsigned char tda827x_ver;
Michael Krufky910bb3e2007-08-27 21:22:20 -030044
Michael Krufky746d97322007-08-25 19:08:45 -030045 struct tda827x_config cfg;
Michael Krufkyb2083192007-05-29 22:54:06 -030046};
47
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080048/*---------------------------------------------------------------------*/
49
Michael Krufky746d97322007-08-25 19:08:45 -030050static void tda8290_i2c_bridge(struct tuner *t, int close)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080051{
Michael Krufky746d97322007-08-25 19:08:45 -030052 struct tda8290_priv *priv = t->priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -030053
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080054 unsigned char enable[2] = { 0x21, 0xC0 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -020055 unsigned char disable[2] = { 0x21, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080056 unsigned char *msg;
57 if(close) {
58 msg = enable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030059 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080060 /* let the bridge stabilize */
61 msleep(20);
62 } else {
63 msg = disable;
Michael Krufkydb8a6952007-08-21 01:24:42 -030064 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080065 }
66}
67
68/*---------------------------------------------------------------------*/
69
Michael Krufky746d97322007-08-25 19:08:45 -030070static void set_audio(struct tuner *t)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -080071{
Michael Krufky746d97322007-08-25 19:08:45 -030072 struct tda8290_priv *priv = t->priv;
Michael Krufky910bb3e2007-08-27 21:22:20 -030073 char* mode;
74
Michael Krufky746d97322007-08-25 19:08:45 -030075 priv->cfg.tda827x_lpsel = 0;
76 if (t->std & V4L2_STD_MN) {
77 priv->cfg.sgIF = 92;
Michael Krufky910bb3e2007-08-27 21:22:20 -030078 priv->tda8290_easy_mode = 0x01;
Michael Krufky746d97322007-08-25 19:08:45 -030079 priv->cfg.tda827x_lpsel = 1;
Michael Krufky910bb3e2007-08-27 21:22:20 -030080 mode = "MN";
Michael Krufky746d97322007-08-25 19:08:45 -030081 } else if (t->std & V4L2_STD_B) {
82 priv->cfg.sgIF = 108;
Michael Krufky910bb3e2007-08-27 21:22:20 -030083 priv->tda8290_easy_mode = 0x02;
84 mode = "B";
Michael Krufky746d97322007-08-25 19:08:45 -030085 } else if (t->std & V4L2_STD_GH) {
86 priv->cfg.sgIF = 124;
Michael Krufky910bb3e2007-08-27 21:22:20 -030087 priv->tda8290_easy_mode = 0x04;
88 mode = "GH";
Michael Krufky746d97322007-08-25 19:08:45 -030089 } else if (t->std & V4L2_STD_PAL_I) {
90 priv->cfg.sgIF = 124;
Michael Krufky910bb3e2007-08-27 21:22:20 -030091 priv->tda8290_easy_mode = 0x08;
92 mode = "I";
Michael Krufky746d97322007-08-25 19:08:45 -030093 } else if (t->std & V4L2_STD_DK) {
94 priv->cfg.sgIF = 124;
Michael Krufky910bb3e2007-08-27 21:22:20 -030095 priv->tda8290_easy_mode = 0x10;
96 mode = "DK";
Michael Krufky746d97322007-08-25 19:08:45 -030097 } else if (t->std & V4L2_STD_SECAM_L) {
98 priv->cfg.sgIF = 124;
Michael Krufky910bb3e2007-08-27 21:22:20 -030099 priv->tda8290_easy_mode = 0x20;
100 mode = "L";
Michael Krufky746d97322007-08-25 19:08:45 -0300101 } else if (t->std & V4L2_STD_SECAM_LC) {
102 priv->cfg.sgIF = 20;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300103 priv->tda8290_easy_mode = 0x40;
104 mode = "LC";
105 } else {
Michael Krufky746d97322007-08-25 19:08:45 -0300106 priv->cfg.sgIF = 124;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300107 priv->tda8290_easy_mode = 0x10;
108 mode = "xx";
109 }
110
Michael Krufky746d97322007-08-25 19:08:45 -0300111 if (t->mode == V4L2_TUNER_RADIO)
112 priv->cfg.sgIF = 88; /* if frequency is 5.5 MHz */
Michael Krufky910bb3e2007-08-27 21:22:20 -0300113
114 tuner_dbg("setting tda8290 to system %s\n", mode);
115}
116
Michael Krufky746d97322007-08-25 19:08:45 -0300117static void tda8290_set_freq(struct tuner *t, unsigned int freq)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300118{
Michael Krufky746d97322007-08-25 19:08:45 -0300119 struct tda8290_priv *priv = t->priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800120 unsigned char soft_reset[] = { 0x00, 0x00 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300121 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800122 unsigned char expert_mode[] = { 0x01, 0x80 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200123 unsigned char agc_out_on[] = { 0x02, 0x00 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800124 unsigned char gainset_off[] = { 0x28, 0x14 };
125 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
126 unsigned char adc_head_6[] = { 0x05, 0x04 };
127 unsigned char adc_head_9[] = { 0x05, 0x02 };
128 unsigned char adc_head_12[] = { 0x05, 0x01 };
129 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
130 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
131 unsigned char gainset_2[] = { 0x28, 0x64 };
132 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
133 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
134 unsigned char if_agc_set[] = { 0x0f, 0x81 };
135 unsigned char addr_adc_sat = 0x1a;
136 unsigned char addr_agc_stat = 0x1d;
137 unsigned char addr_pll_stat = 0x1b;
138 unsigned char adc_sat, agc_stat,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800139 pll_stat;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300140 int i;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800141
Michael Krufky746d97322007-08-25 19:08:45 -0300142 struct analog_parameters params = {
143 .frequency = freq,
144 .mode = t->mode,
145 .audmode = t->audmode,
146 .std = t->std
147 };
Michael Krufky910bb3e2007-08-27 21:22:20 -0300148
Michael Krufky746d97322007-08-25 19:08:45 -0300149 set_audio(t);
150
151 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300152 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
153 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
154 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800155 msleep(1);
156
Michael Krufkyb2083192007-05-29 22:54:06 -0300157 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300158 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
159 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
160 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
Michael Krufkyb2083192007-05-29 22:54:06 -0300161 if (priv->tda8290_easy_mode & 0x60)
Michael Krufkydb8a6952007-08-21 01:24:42 -0300162 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800163 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300164 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
165 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800166
Michael Krufky746d97322007-08-25 19:08:45 -0300167 tda8290_i2c_bridge(t, 1);
168
169 if (t->fe.ops.tuner_ops.set_analog_params)
170 t->fe.ops.tuner_ops.set_analog_params(&t->fe, &params);
171
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300172 for (i = 0; i < 3; i++) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300173 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
174 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300175 if (pll_stat & 0x80) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300176 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
177 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
178 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
179 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300180 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
181 break;
182 } else {
183 tuner_dbg("tda8290 not locked, no signal?\n");
184 msleep(100);
185 }
186 }
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800187 /* adjust headroom resp. gain */
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800188 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
189 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
190 agc_stat, adc_sat, pll_stat & 0x80);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300191 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800192 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300193 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
194 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
195 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
196 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800197 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800198 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
199 agc_stat, pll_stat & 0x80);
Michael Krufky746d97322007-08-25 19:08:45 -0300200 if (priv->cfg.agcf)
201 priv->cfg.agcf(&t->fe);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800202 msleep(100);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300203 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
204 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
205 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
206 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800207 if((agc_stat > 115) || !(pll_stat & 0x80)) {
208 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300209 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
210 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800211 msleep(100);
212 }
213 }
214 }
215
216 /* l/ l' deadlock? */
Michael Krufkyb2083192007-05-29 22:54:06 -0300217 if(priv->tda8290_easy_mode & 0x60) {
Michael Krufkydb8a6952007-08-21 01:24:42 -0300218 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
219 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
220 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
221 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800222 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
Hartmut Hackmann4ac95af2005-11-08 21:38:38 -0800223 tuner_dbg("trying to resolve SECAM L deadlock\n");
Michael Krufkydb8a6952007-08-21 01:24:42 -0300224 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800225 msleep(40);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300226 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800227 }
228 }
229
Michael Krufky746d97322007-08-25 19:08:45 -0300230 tda8290_i2c_bridge(t, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300231 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800232}
233
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800234/*---------------------------------------------------------------------*/
235
Michael Krufky746d97322007-08-25 19:08:45 -0300236static int tda8290_has_signal(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Michael Krufky746d97322007-08-25 19:08:45 -0300238 struct tda8290_priv *priv = t->priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 unsigned char i2c_get_afc[1] = { 0x1B };
241 unsigned char afc = 0;
242
Michael Krufkydb8a6952007-08-21 01:24:42 -0300243 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
244 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300245 return (afc & 0x80)? 65535:0;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300246}
247
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800248/*---------------------------------------------------------------------*/
249
Michael Krufky746d97322007-08-25 19:08:45 -0300250static void tda8290_standby(struct tuner *t)
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700251{
Michael Krufky746d97322007-08-25 19:08:45 -0300252 struct tda8290_priv *priv = t->priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800253 unsigned char cb1[] = { 0x30, 0xD0 };
254 unsigned char tda8290_standby[] = { 0x00, 0x02 };
Hartmut Hackmann0157a9c2006-02-07 06:49:09 -0200255 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
Michael Krufkyb2083192007-05-29 22:54:06 -0300256 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800257
Michael Krufky746d97322007-08-25 19:08:45 -0300258 tda8290_i2c_bridge(t, 1);
Michael Krufkyb2083192007-05-29 22:54:06 -0300259 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800260 cb1[1] = 0x90;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300261 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300262 tda8290_i2c_bridge(t, 0);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300263 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
264 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700265}
266
Michael Krufky746d97322007-08-25 19:08:45 -0300267static void tda8290_init_if(struct tuner *t)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800268{
Michael Krufky746d97322007-08-25 19:08:45 -0300269 struct tda8290_priv *priv = t->priv;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300270
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800271 unsigned char set_VS[] = { 0x30, 0x6F };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300272 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800273 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
274
Michael Krufky746d97322007-08-25 19:08:45 -0300275 if ((t->config == 1) || (t->config == 2))
Michael Krufkydb8a6952007-08-21 01:24:42 -0300276 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300277 else
Michael Krufkydb8a6952007-08-21 01:24:42 -0300278 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
279 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800280}
281
Michael Krufky746d97322007-08-25 19:08:45 -0300282static void tda8290_init_tuner(struct tuner *t)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800283{
Michael Krufky746d97322007-08-25 19:08:45 -0300284 struct tda8290_priv *priv = t->priv;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800285 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800286 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800287 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
Nickolay V. Shmyrev9a741ec2005-11-08 21:37:50 -0800288 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
Michael Krufkyb2083192007-05-29 22:54:06 -0300289 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
Ricardo Cerqueirac2f6f9d2005-11-08 21:37:51 -0800290 .buf=tda8275_init, .len = 14};
Michael Krufkyb2083192007-05-29 22:54:06 -0300291 if (priv->tda827x_ver != 0)
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800292 msg.buf = tda8275a_init;
293
Michael Krufky746d97322007-08-25 19:08:45 -0300294 tda8290_i2c_bridge(t, 1);
Michael Krufkydb8a6952007-08-21 01:24:42 -0300295 i2c_transfer(priv->i2c_props.adap, &msg, 1);
Michael Krufky746d97322007-08-25 19:08:45 -0300296 tda8290_i2c_bridge(t, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800297}
298
299/*---------------------------------------------------------------------*/
300
Michael Krufky746d97322007-08-25 19:08:45 -0300301static void tda8290_release(struct tuner *t)
Michael Krufky024cf532007-06-04 15:20:11 -0300302{
Michael Krufky746d97322007-08-25 19:08:45 -0300303 if (t->fe.ops.tuner_ops.release)
304 t->fe.ops.tuner_ops.release(&t->fe);
Michael Krufky910bb3e2007-08-27 21:22:20 -0300305
Michael Krufky746d97322007-08-25 19:08:45 -0300306 kfree(t->priv);
307 t->priv = NULL;
Michael Krufky024cf532007-06-04 15:20:11 -0300308}
309
Michael Krufky746d97322007-08-25 19:08:45 -0300310static struct tuner_operations tda8290_tuner_ops = {
311 .set_tv_freq = tda8290_set_freq,
312 .set_radio_freq = tda8290_set_freq,
313 .has_signal = tda8290_has_signal,
314 .standby = tda8290_standby,
315 .release = tda8290_release,
Michael Krufky7fd8b262007-06-06 16:15:15 -0300316};
317
Michael Krufky746d97322007-08-25 19:08:45 -0300318int tda8290_attach(struct tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Michael Krufkyb2083192007-05-29 22:54:06 -0300320 struct tda8290_priv *priv = NULL;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800321 u8 data;
322 int i, ret, tuners_found;
323 u32 tuner_addrs;
324 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Michael Krufkyb2083192007-05-29 22:54:06 -0300326 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
327 if (priv == NULL)
Michael Krufky746d97322007-08-25 19:08:45 -0300328 return -ENOMEM;
329 t->priv = priv;
Michael Krufkyb2083192007-05-29 22:54:06 -0300330
Michael Krufky746d97322007-08-25 19:08:45 -0300331 priv->i2c_props.addr = t->i2c.addr;
332 priv->i2c_props.adap = t->i2c.adapter;
333 priv->cfg.config = &t->config;
334 priv->cfg.tuner_callback = t->tuner_callback;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300335
Michael Krufky746d97322007-08-25 19:08:45 -0300336 tda8290_i2c_bridge(t, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800337 /* probe for tuner chip */
338 tuners_found = 0;
339 tuner_addrs = 0;
340 for (i=0x60; i<= 0x63; i++) {
341 msg.addr = i;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300342 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800343 if (ret == 1) {
344 tuners_found++;
345 tuner_addrs = (tuner_addrs << 8) + i;
346 }
347 }
348 /* if there is more than one tuner, we expect the right one is
349 behind the bridge and we choose the highest address that doesn't
350 give a response now
351 */
Michael Krufky746d97322007-08-25 19:08:45 -0300352 tda8290_i2c_bridge(t, 0);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800353 if(tuners_found > 1)
354 for (i = 0; i < tuners_found; i++) {
355 msg.addr = tuner_addrs & 0xff;
Michael Krufkydb8a6952007-08-21 01:24:42 -0300356 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800357 if(ret == 1)
358 tuner_addrs = tuner_addrs >> 8;
359 else
360 break;
361 }
362 if (tuner_addrs == 0) {
363 tuner_addrs = 0x61;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300364 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
Nickolay V. Shmyrev01cb9632005-11-08 21:38:00 -0800365 tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800366 } else {
367 tuner_addrs = tuner_addrs & 0xff;
Michael Krufky910bb3e2007-08-27 21:22:20 -0300368 tuner_info("setting tuner address to %x\n", tuner_addrs);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800369 }
Michael Krufkyb2083192007-05-29 22:54:06 -0300370 priv->tda827x_addr = tuner_addrs;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800371 msg.addr = tuner_addrs;
372
Michael Krufky746d97322007-08-25 19:08:45 -0300373 tda8290_i2c_bridge(t, 1);
374
Michael Krufkydb8a6952007-08-21 01:24:42 -0300375 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800376 if( ret != 1)
Michael Krufky910bb3e2007-08-27 21:22:20 -0300377 tuner_warn("TDA827x access failed!\n");
378
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800379 if ((data & 0x3c) == 0) {
Michael Krufky746d97322007-08-25 19:08:45 -0300380 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300381 priv->tda827x_ver = 0;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800382 } else {
Michael Krufky746d97322007-08-25 19:08:45 -0300383 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
Michael Krufkyb2083192007-05-29 22:54:06 -0300384 priv->tda827x_ver = 2;
Hartmut Hackmannde48eeb2005-11-08 21:37:48 -0800385 }
Michael Krufky746d97322007-08-25 19:08:45 -0300386 tda827x_attach(&t->fe, priv->tda827x_addr,
387 priv->i2c_props.adap, &priv->cfg);
Michael Krufky7fd8b262007-06-06 16:15:15 -0300388
Michael Krufky746d97322007-08-25 19:08:45 -0300389 /* FIXME: tda827x module doesn't probe the tuner until
390 * tda827x_initial_sleep is called
391 */
392 if (t->fe.ops.tuner_ops.sleep)
393 t->fe.ops.tuner_ops.sleep(&t->fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Michael Krufky746d97322007-08-25 19:08:45 -0300395 memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations));
396
397 tuner_info("type set to %s\n", t->i2c.name);
398
399 priv->cfg.tda827x_lpsel = 0;
400 t->mode = V4L2_TUNER_ANALOG_TV;
401
402 tda8290_init_tuner(t);
403 tda8290_init_if(t);
404 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
Michael Krufky746d97322007-08-25 19:08:45 -0300407int tda8290_probe(struct tuner *t)
Hartmut Hackmann95736032005-11-08 21:38:00 -0800408{
Michael Krufky910bb3e2007-08-27 21:22:20 -0300409 struct tuner_i2c_props i2c_props = {
Michael Krufky746d97322007-08-25 19:08:45 -0300410 .adap = t->i2c.adapter,
411 .addr = t->i2c.addr
Michael Krufky910bb3e2007-08-27 21:22:20 -0300412 };
Michael Krufkydb8a6952007-08-21 01:24:42 -0300413
Hartmut Hackmann44fd06f2006-02-27 00:09:11 -0300414 unsigned char soft_reset[] = { 0x00, 0x00 };
415 unsigned char easy_mode_b[] = { 0x01, 0x02 };
416 unsigned char easy_mode_g[] = { 0x01, 0x04 };
417 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
Hartmut Hackmann95736032005-11-08 21:38:00 -0800418 unsigned char addr_dto_lsb = 0x07;
419 unsigned char data;
420
Michael Krufky910bb3e2007-08-27 21:22:20 -0300421 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
422 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
423 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
424 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800425 if (data == 0) {
Michael Krufky910bb3e2007-08-27 21:22:20 -0300426 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
427 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
428 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
429 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800430 if (data == 0x7b) {
431 return 0;
432 }
433 }
Michael Krufky910bb3e2007-08-27 21:22:20 -0300434 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
Hartmut Hackmann95736032005-11-08 21:38:00 -0800435 return -1;
436}
437
Michael Krufky910bb3e2007-08-27 21:22:20 -0300438EXPORT_SYMBOL_GPL(tda8290_probe);
439EXPORT_SYMBOL_GPL(tda8290_attach);
440
441MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
442MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann");
443MODULE_LICENSE("GPL");
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445/*
446 * Overrides for Emacs so that we follow Linus's tabbing style.
447 * ---------------------------------------------------------------------------
448 * Local variables:
449 * c-basic-offset: 8
450 * End:
451 */