Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 2 | |
| 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 Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 19 | |
| 20 | This "tda8290" module was split apart from the original "tuner" module. |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
Hans Verkuil | 7f6adea | 2009-02-19 17:31:17 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 27 | #include "tuner-i2c.h" |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 28 | #include "tda8290.h" |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 29 | #include "tda827x.h" |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 30 | #include "tda18271.h" |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 31 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 32 | static int debug; |
| 33 | module_param(debug, int, 0644); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 34 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); |
| 35 | |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 36 | static int deemphasis_50; |
Henk Vergonet | b450b92 | 2009-09-27 18:19:58 -0300 | [diff] [blame] | 37 | module_param(deemphasis_50, int, 0644); |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 38 | MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis"); |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* ---------------------------------------------------------------------- */ |
| 41 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 42 | struct tda8290_priv { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 43 | struct tuner_i2c_props i2c_props; |
| 44 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 45 | unsigned char tda8290_easy_mode; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 46 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 47 | unsigned char tda827x_addr; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 48 | |
| 49 | unsigned char ver; |
| 50 | #define TDA8290 1 |
| 51 | #define TDA8295 2 |
| 52 | #define TDA8275 4 |
| 53 | #define TDA8275A 8 |
| 54 | #define TDA18271 16 |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 55 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 56 | struct tda827x_config cfg; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 59 | /*---------------------------------------------------------------------*/ |
| 60 | |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 61 | static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 62 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 63 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 64 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 65 | unsigned char enable[2] = { 0x21, 0xC0 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 66 | unsigned char disable[2] = { 0x21, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 67 | unsigned char *msg; |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 68 | |
| 69 | if (close) { |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 70 | msg = enable; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 71 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 72 | /* let the bridge stabilize */ |
| 73 | msleep(20); |
| 74 | } else { |
| 75 | msg = disable; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 76 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 77 | } |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 78 | |
| 79 | return 0; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 82 | static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 83 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 84 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 85 | |
| 86 | unsigned char enable[2] = { 0x45, 0xc1 }; |
| 87 | unsigned char disable[2] = { 0x46, 0x00 }; |
| 88 | unsigned char buf[3] = { 0x45, 0x01, 0x00 }; |
| 89 | unsigned char *msg; |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 90 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 91 | if (close) { |
| 92 | msg = enable; |
| 93 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
| 94 | /* let the bridge stabilize */ |
| 95 | msleep(20); |
| 96 | } else { |
| 97 | msg = disable; |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 98 | tuner_i2c_xfer_send_recv(&priv->i2c_props, msg, 1, &msg[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 99 | |
| 100 | buf[2] = msg[1]; |
| 101 | buf[2] &= ~0x04; |
| 102 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 3); |
| 103 | msleep(5); |
| 104 | |
| 105 | msg[1] |= 0x04; |
| 106 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
| 107 | } |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 108 | |
| 109 | return 0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 110 | } |
| 111 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 112 | /*---------------------------------------------------------------------*/ |
| 113 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 114 | static void set_audio(struct dvb_frontend *fe, |
| 115 | struct analog_parameters *params) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 116 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 117 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 118 | char* mode; |
| 119 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 120 | if (params->std & V4L2_STD_MN) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 121 | priv->tda8290_easy_mode = 0x01; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 122 | mode = "MN"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 123 | } else if (params->std & V4L2_STD_B) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 124 | priv->tda8290_easy_mode = 0x02; |
| 125 | mode = "B"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 126 | } else if (params->std & V4L2_STD_GH) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 127 | priv->tda8290_easy_mode = 0x04; |
| 128 | mode = "GH"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 129 | } else if (params->std & V4L2_STD_PAL_I) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 130 | priv->tda8290_easy_mode = 0x08; |
| 131 | mode = "I"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 132 | } else if (params->std & V4L2_STD_DK) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 133 | priv->tda8290_easy_mode = 0x10; |
| 134 | mode = "DK"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 135 | } else if (params->std & V4L2_STD_SECAM_L) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 136 | priv->tda8290_easy_mode = 0x20; |
| 137 | mode = "L"; |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 138 | } else if (params->std & V4L2_STD_SECAM_LC) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 139 | priv->tda8290_easy_mode = 0x40; |
| 140 | mode = "LC"; |
| 141 | } else { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 142 | priv->tda8290_easy_mode = 0x10; |
| 143 | mode = "xx"; |
| 144 | } |
| 145 | |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 146 | if (params->mode == V4L2_TUNER_RADIO) { |
Michael Krufky | 3f76cf8 | 2010-01-10 18:13:33 -0300 | [diff] [blame] | 147 | /* Set TDA8295 to FM radio; Start TDA8290 with MN values */ |
| 148 | priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01; |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 149 | tuner_dbg("setting to radio FM\n"); |
| 150 | } else { |
| 151 | tuner_dbg("setting tda829x to system %s\n", mode); |
| 152 | } |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 153 | } |
| 154 | |
Mauro Carvalho Chehab | 4c27f1a | 2009-01-05 01:23:50 -0300 | [diff] [blame] | 155 | static struct { |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 156 | unsigned char seq[2]; |
| 157 | } fm_mode[] = { |
| 158 | { { 0x01, 0x81} }, /* Put device into expert mode */ |
| 159 | { { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */ |
| 160 | { { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */ |
| 161 | { { 0x05, 0x04} }, /* ADC headroom */ |
| 162 | { { 0x06, 0x10} }, /* group delay flat */ |
| 163 | |
| 164 | { { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */ |
| 165 | { { 0x08, 0x00} }, |
| 166 | { { 0x09, 0x80} }, |
| 167 | { { 0x0a, 0xda} }, |
| 168 | { { 0x0b, 0x4b} }, |
| 169 | { { 0x0c, 0x68} }, |
| 170 | |
| 171 | { { 0x0d, 0x00} }, /* PLL off, no video carrier detect */ |
| 172 | { { 0x14, 0x00} }, /* disable auto mute if no video */ |
| 173 | }; |
| 174 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 175 | static void tda8290_set_params(struct dvb_frontend *fe, |
| 176 | struct analog_parameters *params) |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 177 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 178 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 179 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 180 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 181 | unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 182 | unsigned char expert_mode[] = { 0x01, 0x80 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 183 | unsigned char agc_out_on[] = { 0x02, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 184 | unsigned char gainset_off[] = { 0x28, 0x14 }; |
| 185 | unsigned char if_agc_spd[] = { 0x0f, 0x88 }; |
| 186 | unsigned char adc_head_6[] = { 0x05, 0x04 }; |
| 187 | unsigned char adc_head_9[] = { 0x05, 0x02 }; |
| 188 | unsigned char adc_head_12[] = { 0x05, 0x01 }; |
| 189 | unsigned char pll_bw_nom[] = { 0x0d, 0x47 }; |
| 190 | unsigned char pll_bw_low[] = { 0x0d, 0x27 }; |
| 191 | unsigned char gainset_2[] = { 0x28, 0x64 }; |
| 192 | unsigned char agc_rst_on[] = { 0x0e, 0x0b }; |
| 193 | unsigned char agc_rst_off[] = { 0x0e, 0x09 }; |
| 194 | unsigned char if_agc_set[] = { 0x0f, 0x81 }; |
| 195 | unsigned char addr_adc_sat = 0x1a; |
| 196 | unsigned char addr_agc_stat = 0x1d; |
| 197 | unsigned char addr_pll_stat = 0x1b; |
| 198 | unsigned char adc_sat, agc_stat, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 199 | pll_stat; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 200 | int i; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 201 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 202 | set_audio(fe, params); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 203 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 204 | if (priv->cfg.config) |
Hartmut Hackmann | 7bff4b4 | 2008-04-22 14:46:08 -0300 | [diff] [blame] | 205 | tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 206 | tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2); |
| 207 | tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2); |
| 208 | tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 209 | msleep(1); |
| 210 | |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 211 | if (params->mode == V4L2_TUNER_RADIO) { |
Mauro Carvalho Chehab | 9af0ef2 | 2008-12-08 10:36:57 -0300 | [diff] [blame] | 212 | unsigned char deemphasis[] = { 0x13, 1 }; |
| 213 | |
| 214 | /* FIXME: allow using a different deemphasis */ |
| 215 | |
| 216 | if (deemphasis_50) |
| 217 | deemphasis[1] = 2; |
| 218 | |
| 219 | for (i = 0; i < ARRAY_SIZE(fm_mode); i++) |
| 220 | tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2); |
| 221 | |
| 222 | tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2); |
| 223 | } else { |
| 224 | expert_mode[1] = priv->tda8290_easy_mode + 0x80; |
| 225 | tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2); |
| 226 | tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2); |
| 227 | tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2); |
| 228 | if (priv->tda8290_easy_mode & 0x60) |
| 229 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2); |
| 230 | else |
| 231 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2); |
| 232 | tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2); |
| 233 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 234 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 235 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 236 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 237 | if (fe->ops.tuner_ops.set_analog_params) |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 238 | fe->ops.tuner_ops.set_analog_params(fe, params); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 239 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 240 | for (i = 0; i < 3; i++) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 241 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 242 | &addr_pll_stat, 1, &pll_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 243 | if (pll_stat & 0x80) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 244 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 245 | &addr_adc_sat, 1, |
| 246 | &adc_sat, 1); |
| 247 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 248 | &addr_agc_stat, 1, |
| 249 | &agc_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 250 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); |
| 251 | break; |
| 252 | } else { |
| 253 | tuner_dbg("tda8290 not locked, no signal?\n"); |
| 254 | msleep(100); |
| 255 | } |
| 256 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 257 | /* adjust headroom resp. gain */ |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 258 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { |
| 259 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", |
| 260 | agc_stat, adc_sat, pll_stat & 0x80); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 261 | tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 262 | msleep(100); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 263 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 264 | &addr_agc_stat, 1, &agc_stat, 1); |
| 265 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 266 | &addr_pll_stat, 1, &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 267 | if ((agc_stat > 115) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 268 | tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", |
| 269 | agc_stat, pll_stat & 0x80); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 270 | if (priv->cfg.agcf) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 271 | priv->cfg.agcf(fe); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 272 | msleep(100); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 273 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 274 | &addr_agc_stat, 1, |
| 275 | &agc_stat, 1); |
| 276 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 277 | &addr_pll_stat, 1, |
| 278 | &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 279 | if((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 280 | tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 281 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2); |
| 282 | tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 283 | msleep(100); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* l/ l' deadlock? */ |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 289 | if(priv->tda8290_easy_mode & 0x60) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 290 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 291 | &addr_adc_sat, 1, |
| 292 | &adc_sat, 1); |
| 293 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 294 | &addr_pll_stat, 1, |
| 295 | &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 296 | if ((adc_sat > 20) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 297 | tuner_dbg("trying to resolve SECAM L deadlock\n"); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 298 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 299 | msleep(40); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 300 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 304 | tda8290_i2c_bridge(fe, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 305 | tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 308 | /*---------------------------------------------------------------------*/ |
| 309 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 310 | static void tda8295_power(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 311 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 312 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 313 | unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */ |
| 314 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 315 | tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 316 | |
| 317 | if (enable) |
| 318 | buf[1] = 0x01; |
| 319 | else |
| 320 | buf[1] = 0x03; |
| 321 | |
| 322 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 323 | } |
| 324 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 325 | static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 326 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 327 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 328 | unsigned char buf[] = { 0x01, 0x00 }; |
| 329 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 330 | tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 331 | |
| 332 | if (enable) |
| 333 | buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */ |
| 334 | else |
| 335 | buf[1] = 0x00; /* reset active bit */ |
| 336 | |
| 337 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 338 | } |
| 339 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 340 | static void tda8295_set_video_std(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 341 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 342 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 343 | unsigned char buf[] = { 0x00, priv->tda8290_easy_mode }; |
| 344 | |
| 345 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 346 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 347 | tda8295_set_easy_mode(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 348 | msleep(20); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 349 | tda8295_set_easy_mode(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /*---------------------------------------------------------------------*/ |
| 353 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 354 | static void tda8295_agc1_out(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 355 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 356 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 357 | unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */ |
| 358 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 359 | tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 360 | |
| 361 | if (enable) |
| 362 | buf[1] &= ~0x40; |
| 363 | else |
| 364 | buf[1] |= 0x40; |
| 365 | |
| 366 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 367 | } |
| 368 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 369 | static void tda8295_agc2_out(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 370 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 371 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 372 | unsigned char set_gpio_cf[] = { 0x44, 0x00 }; |
| 373 | unsigned char set_gpio_val[] = { 0x46, 0x00 }; |
| 374 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 375 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 376 | &set_gpio_cf[0], 1, &set_gpio_cf[1], 1); |
| 377 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 378 | &set_gpio_val[0], 1, &set_gpio_val[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 379 | |
| 380 | set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */ |
| 381 | |
| 382 | if (enable) { |
| 383 | set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */ |
| 384 | set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */ |
| 385 | } |
| 386 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2); |
| 387 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2); |
| 388 | } |
| 389 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 390 | static int tda8295_has_signal(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 391 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 392 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 393 | |
| 394 | unsigned char hvpll_stat = 0x26; |
| 395 | unsigned char ret; |
| 396 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 397 | tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 398 | return (ret & 0x01) ? 65535 : 0; |
| 399 | } |
| 400 | |
| 401 | /*---------------------------------------------------------------------*/ |
| 402 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 403 | static void tda8295_set_params(struct dvb_frontend *fe, |
| 404 | struct analog_parameters *params) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 405 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 406 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 407 | |
| 408 | unsigned char blanking_mode[] = { 0x1d, 0x00 }; |
| 409 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 410 | set_audio(fe, params); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 411 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 412 | tuner_dbg("%s: freq = %d\n", __func__, params->frequency); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 413 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 414 | tda8295_power(fe, 1); |
| 415 | tda8295_agc1_out(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 416 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 417 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 418 | &blanking_mode[0], 1, &blanking_mode[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 419 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 420 | tda8295_set_video_std(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 421 | |
| 422 | blanking_mode[1] = 0x03; |
| 423 | tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2); |
| 424 | msleep(20); |
| 425 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 426 | tda8295_i2c_bridge(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 427 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 428 | if (fe->ops.tuner_ops.set_analog_params) |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 429 | fe->ops.tuner_ops.set_analog_params(fe, params); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 430 | |
| 431 | if (priv->cfg.agcf) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 432 | priv->cfg.agcf(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 433 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 434 | if (tda8295_has_signal(fe)) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 435 | tuner_dbg("tda8295 is locked\n"); |
| 436 | else |
| 437 | tuner_dbg("tda8295 not locked, no signal?\n"); |
| 438 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 439 | tda8295_i2c_bridge(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /*---------------------------------------------------------------------*/ |
| 443 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 444 | static int tda8290_has_signal(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 446 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | unsigned char i2c_get_afc[1] = { 0x1B }; |
| 449 | unsigned char afc = 0; |
| 450 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 451 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 452 | i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 453 | return (afc & 0x80)? 65535:0; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 454 | } |
| 455 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 456 | /*---------------------------------------------------------------------*/ |
| 457 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 458 | static void tda8290_standby(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 459 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 460 | struct tda8290_priv *priv = fe->analog_demod_priv; |
| 461 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 462 | unsigned char cb1[] = { 0x30, 0xD0 }; |
| 463 | unsigned char tda8290_standby[] = { 0x00, 0x02 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 464 | unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 465 | struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 466 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 467 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 468 | if (priv->ver & TDA8275A) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 469 | cb1[1] = 0x90; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 470 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 471 | tda8290_i2c_bridge(fe, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 472 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); |
| 473 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 476 | static void tda8295_standby(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 477 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 478 | tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 479 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 480 | tda8295_power(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 481 | } |
| 482 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 483 | static void tda8290_init_if(struct dvb_frontend *fe) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 484 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 485 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 486 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 487 | unsigned char set_VS[] = { 0x30, 0x6F }; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 488 | unsigned char set_GP00_CF[] = { 0x20, 0x01 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 489 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
| 490 | |
Hartmut Hackmann | 7bff4b4 | 2008-04-22 14:46:08 -0300 | [diff] [blame] | 491 | if ((priv->cfg.config == 1) || (priv->cfg.config == 2)) |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 492 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 493 | else |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 494 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); |
| 495 | tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 498 | static void tda8295_init_if(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 499 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 500 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 501 | |
| 502 | static unsigned char set_adc_ctl[] = { 0x33, 0x14 }; |
| 503 | static unsigned char set_adc_ctl2[] = { 0x34, 0x00 }; |
| 504 | static unsigned char set_pll_reg6[] = { 0x3e, 0x63 }; |
| 505 | static unsigned char set_pll_reg0[] = { 0x38, 0x23 }; |
| 506 | static unsigned char set_pll_reg7[] = { 0x3f, 0x01 }; |
| 507 | static unsigned char set_pll_reg10[] = { 0x42, 0x61 }; |
| 508 | static unsigned char set_gpio_reg0[] = { 0x44, 0x0b }; |
| 509 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 510 | tda8295_power(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 511 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 512 | tda8295_set_easy_mode(fe, 0); |
| 513 | tda8295_set_video_std(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 514 | |
| 515 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2); |
| 516 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2); |
| 517 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2); |
| 518 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2); |
| 519 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2); |
| 520 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2); |
| 521 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2); |
| 522 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 523 | tda8295_agc1_out(fe, 0); |
| 524 | tda8295_agc2_out(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 525 | } |
| 526 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 527 | static void tda8290_init_tuner(struct dvb_frontend *fe) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 528 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 529 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 530 | unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 531 | 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 532 | unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 533 | 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 534 | struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, |
Ricardo Cerqueira | c2f6f9d | 2005-11-08 21:37:51 -0800 | [diff] [blame] | 535 | .buf=tda8275_init, .len = 14}; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 536 | if (priv->ver & TDA8275A) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 537 | msg.buf = tda8275a_init; |
| 538 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 539 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 540 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 541 | tda8290_i2c_bridge(fe, 0); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /*---------------------------------------------------------------------*/ |
| 545 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 546 | static void tda829x_release(struct dvb_frontend *fe) |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 547 | { |
Michael Krufky | a4f263b | 2008-01-06 15:52:56 -0300 | [diff] [blame] | 548 | struct tda8290_priv *priv = fe->analog_demod_priv; |
| 549 | |
Michael Krufky | 006ed1e | 2008-01-09 10:44:27 -0300 | [diff] [blame] | 550 | /* only try to release the tuner if we've |
| 551 | * attached it from within this module */ |
| 552 | if (priv->ver & (TDA18271 | TDA8275 | TDA8275A)) |
Michael Krufky | a4f263b | 2008-01-06 15:52:56 -0300 | [diff] [blame] | 553 | if (fe->ops.tuner_ops.release) |
| 554 | fe->ops.tuner_ops.release(fe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 555 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 556 | kfree(fe->analog_demod_priv); |
| 557 | fe->analog_demod_priv = NULL; |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 558 | } |
| 559 | |
Michael Krufky | f21e0d7 | 2008-01-02 03:01:54 -0300 | [diff] [blame] | 560 | static struct tda18271_config tda829x_tda18271_config = { |
| 561 | .gate = TDA18271_GATE_ANALOG, |
| 562 | }; |
| 563 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 564 | static int tda829x_find_tuner(struct dvb_frontend *fe) |
| 565 | { |
| 566 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 567 | struct analog_demod_ops *analog_ops = &fe->ops.analog_ops; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 568 | int i, ret, tuners_found; |
| 569 | u32 tuner_addrs; |
| 570 | u8 data; |
| 571 | struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 }; |
| 572 | |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 573 | if (!analog_ops->i2c_gate_ctrl) { |
| 574 | printk(KERN_ERR "tda8290: no gate control were provided!\n"); |
| 575 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 576 | return -EINVAL; |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 577 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 578 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 579 | analog_ops->i2c_gate_ctrl(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 580 | |
| 581 | /* probe for tuner chip */ |
| 582 | tuners_found = 0; |
| 583 | tuner_addrs = 0; |
| 584 | for (i = 0x60; i <= 0x63; i++) { |
| 585 | msg.addr = i; |
| 586 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 587 | if (ret == 1) { |
| 588 | tuners_found++; |
| 589 | tuner_addrs = (tuner_addrs << 8) + i; |
| 590 | } |
| 591 | } |
| 592 | /* if there is more than one tuner, we expect the right one is |
| 593 | behind the bridge and we choose the highest address that doesn't |
| 594 | give a response now |
| 595 | */ |
| 596 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 597 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 598 | |
| 599 | if (tuners_found > 1) |
| 600 | for (i = 0; i < tuners_found; i++) { |
| 601 | msg.addr = tuner_addrs & 0xff; |
| 602 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 603 | if (ret == 1) |
| 604 | tuner_addrs = tuner_addrs >> 8; |
| 605 | else |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | if (tuner_addrs == 0) { |
| 610 | tuner_addrs = 0x60; |
| 611 | tuner_info("could not clearly identify tuner address, " |
| 612 | "defaulting to %x\n", tuner_addrs); |
| 613 | } else { |
| 614 | tuner_addrs = tuner_addrs & 0xff; |
| 615 | tuner_info("setting tuner address to %x\n", tuner_addrs); |
| 616 | } |
| 617 | priv->tda827x_addr = tuner_addrs; |
| 618 | msg.addr = tuner_addrs; |
| 619 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 620 | analog_ops->i2c_gate_ctrl(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 621 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 622 | |
| 623 | if (ret != 1) { |
| 624 | tuner_warn("tuner access failed!\n"); |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 625 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 626 | return -EREMOTEIO; |
| 627 | } |
| 628 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 629 | if ((data == 0x83) || (data == 0x84)) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 630 | priv->ver |= TDA18271; |
Michael Krufky | adcc4b3 | 2009-03-04 19:42:06 -0300 | [diff] [blame] | 631 | tda829x_tda18271_config.config = priv->cfg.config; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 632 | dvb_attach(tda18271_attach, fe, priv->tda827x_addr, |
| 633 | priv->i2c_props.adap, &tda829x_tda18271_config); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 634 | } else { |
| 635 | if ((data & 0x3c) == 0) |
| 636 | priv->ver |= TDA8275; |
| 637 | else |
| 638 | priv->ver |= TDA8275A; |
| 639 | |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 640 | dvb_attach(tda827x_attach, fe, priv->tda827x_addr, |
| 641 | priv->i2c_props.adap, &priv->cfg); |
Hartmut Hackmann | 7bff4b4 | 2008-04-22 14:46:08 -0300 | [diff] [blame] | 642 | priv->cfg.switch_addr = priv->i2c_props.addr; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 643 | } |
Michael Krufky | 6881647 | 2007-12-08 16:25:41 -0300 | [diff] [blame] | 644 | if (fe->ops.tuner_ops.init) |
| 645 | fe->ops.tuner_ops.init(fe); |
Michael Krufky | 63c2548 | 2007-11-23 15:08:11 -0300 | [diff] [blame] | 646 | |
Michael Krufky | 6881647 | 2007-12-08 16:25:41 -0300 | [diff] [blame] | 647 | if (fe->ops.tuner_ops.sleep) |
| 648 | fe->ops.tuner_ops.sleep(fe); |
Michael Krufky | 63c2548 | 2007-11-23 15:08:11 -0300 | [diff] [blame] | 649 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 650 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 651 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 655 | static int tda8290_probe(struct tuner_i2c_props *i2c_props) |
| 656 | { |
| 657 | #define TDA8290_ID 0x89 |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 658 | u8 reg = 0x1f, id; |
| 659 | struct i2c_msg msg_read[] = { |
| 660 | { .addr = 0x4b, .flags = 0, .len = 1, .buf = ® }, |
| 661 | { .addr = 0x4b, .flags = I2C_M_RD, .len = 1, .buf = &id }, |
| 662 | }; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 663 | |
| 664 | /* detect tda8290 */ |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 665 | if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) { |
| 666 | printk(KERN_WARNING "%s: tda8290 couldn't read register 0x%02x\n", |
| 667 | __func__, reg); |
| 668 | return -ENODEV; |
| 669 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 670 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 671 | if (id == TDA8290_ID) { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 672 | if (debug) |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 673 | printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n", |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 674 | __func__, i2c_adapter_id(i2c_props->adap), |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 675 | i2c_props->addr); |
| 676 | return 0; |
| 677 | } |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 678 | return -ENODEV; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static int tda8295_probe(struct tuner_i2c_props *i2c_props) |
| 682 | { |
| 683 | #define TDA8295_ID 0x8a |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 684 | #define TDA8295C2_ID 0x8b |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 685 | u8 reg = 0x2f, id; |
| 686 | struct i2c_msg msg_read[] = { |
| 687 | { .addr = 0x4b, .flags = 0, .len = 1, .buf = ® }, |
| 688 | { .addr = 0x4b, .flags = I2C_M_RD, .len = 1, .buf = &id }, |
| 689 | }; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 690 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 691 | /* detect tda8290 */ |
| 692 | if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) { |
| 693 | printk(KERN_WARNING "%s: tda8290 couldn't read register 0x%02x\n", |
| 694 | __func__, reg); |
| 695 | return -ENODEV; |
| 696 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 697 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 698 | if ((id & 0xfe) == TDA8295_ID) { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 699 | if (debug) |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 700 | printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n", |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 701 | __func__, (id == TDA8295_ID) ? |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 702 | "tda8295c1" : "tda8295c2", |
| 703 | i2c_adapter_id(i2c_props->adap), |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 704 | i2c_props->addr); |
| 705 | return 0; |
| 706 | } |
| 707 | |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 708 | return -ENODEV; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 709 | } |
| 710 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 711 | static struct analog_demod_ops tda8290_ops = { |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 712 | .set_params = tda8290_set_params, |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 713 | .has_signal = tda8290_has_signal, |
| 714 | .standby = tda8290_standby, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 715 | .release = tda829x_release, |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 716 | .i2c_gate_ctrl = tda8290_i2c_bridge, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 717 | }; |
| 718 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 719 | static struct analog_demod_ops tda8295_ops = { |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 720 | .set_params = tda8295_set_params, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 721 | .has_signal = tda8295_has_signal, |
| 722 | .standby = tda8295_standby, |
| 723 | .release = tda829x_release, |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 724 | .i2c_gate_ctrl = tda8295_i2c_bridge, |
Michael Krufky | 7fd8b26 | 2007-06-06 16:15:15 -0300 | [diff] [blame] | 725 | }; |
| 726 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 727 | struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe, |
| 728 | struct i2c_adapter *i2c_adap, u8 i2c_addr, |
| 729 | struct tda829x_config *cfg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | { |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 731 | struct tda8290_priv *priv = NULL; |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 732 | char *name; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 733 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 734 | priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); |
| 735 | if (priv == NULL) |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 736 | return NULL; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 737 | fe->analog_demod_priv = priv; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 738 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 739 | priv->i2c_props.addr = i2c_addr; |
| 740 | priv->i2c_props.adap = i2c_adap; |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 741 | priv->i2c_props.name = "tda829x"; |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 742 | if (cfg) |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 743 | priv->cfg.config = cfg->lna_cfg; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 744 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 745 | if (tda8290_probe(&priv->i2c_props) == 0) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 746 | priv->ver = TDA8290; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 747 | memcpy(&fe->ops.analog_ops, &tda8290_ops, |
| 748 | sizeof(struct analog_demod_ops)); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 749 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 750 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 751 | if (tda8295_probe(&priv->i2c_props) == 0) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 752 | priv->ver = TDA8295; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 753 | memcpy(&fe->ops.analog_ops, &tda8295_ops, |
| 754 | sizeof(struct analog_demod_ops)); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 755 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 756 | |
Mauro Carvalho Chehab | 9d700a0 | 2011-01-13 14:01:39 -0300 | [diff] [blame^] | 757 | if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) { |
| 758 | tda8295_power(fe, 1); |
| 759 | if (tda829x_find_tuner(fe) < 0) |
| 760 | goto fail; |
Mauro Carvalho Chehab | 47ab285 | 2011-01-13 12:02:00 -0300 | [diff] [blame] | 761 | } |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 762 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 763 | switch (priv->ver) { |
Michael Krufky | c907627 | 2007-12-24 04:36:14 -0300 | [diff] [blame] | 764 | case TDA8290: |
| 765 | name = "tda8290"; |
| 766 | break; |
| 767 | case TDA8295: |
| 768 | name = "tda8295"; |
| 769 | break; |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 770 | case TDA8290 | TDA8275: |
| 771 | name = "tda8290+75"; |
| 772 | break; |
| 773 | case TDA8295 | TDA8275: |
| 774 | name = "tda8295+75"; |
| 775 | break; |
| 776 | case TDA8290 | TDA8275A: |
| 777 | name = "tda8290+75a"; |
| 778 | break; |
| 779 | case TDA8295 | TDA8275A: |
| 780 | name = "tda8295+75a"; |
| 781 | break; |
| 782 | case TDA8290 | TDA18271: |
| 783 | name = "tda8290+18271"; |
| 784 | break; |
| 785 | case TDA8295 | TDA18271: |
| 786 | name = "tda8295+18271"; |
| 787 | break; |
| 788 | default: |
| 789 | goto fail; |
| 790 | } |
| 791 | tuner_info("type set to %s\n", name); |
| 792 | |
Michael Krufky | 0f2ce98 | 2008-01-21 10:55:37 -0300 | [diff] [blame] | 793 | fe->ops.analog_ops.info.name = name; |
| 794 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 795 | if (priv->ver & TDA8290) { |
Michael Krufky | 439b72b | 2009-01-05 18:25:04 -0300 | [diff] [blame] | 796 | if (priv->ver & (TDA8275 | TDA8275A)) |
| 797 | tda8290_init_tuner(fe); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 798 | tda8290_init_if(fe); |
| 799 | } else if (priv->ver & TDA8295) |
| 800 | tda8295_init_if(fe); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 801 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 802 | return fe; |
Michael Krufky | fa746aee | 2007-12-09 05:16:10 -0300 | [diff] [blame] | 803 | |
| 804 | fail: |
Mauro Carvalho Chehab | 9d700a0 | 2011-01-13 14:01:39 -0300 | [diff] [blame^] | 805 | memset(&fe->ops.analog_ops, 0, sizeof(struct analog_demod_ops)); |
| 806 | |
Michael Krufky | fa746aee | 2007-12-09 05:16:10 -0300 | [diff] [blame] | 807 | tda829x_release(fe); |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 808 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 810 | EXPORT_SYMBOL_GPL(tda829x_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 812 | int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr) |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 813 | { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 814 | struct tuner_i2c_props i2c_props = { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 815 | .adap = i2c_adap, |
| 816 | .addr = i2c_addr, |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 817 | }; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 818 | |
Hartmut Hackmann | 44fd06f | 2006-02-27 00:09:11 -0300 | [diff] [blame] | 819 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 820 | unsigned char easy_mode_b[] = { 0x01, 0x02 }; |
| 821 | unsigned char easy_mode_g[] = { 0x01, 0x04 }; |
| 822 | unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 }; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 823 | unsigned char addr_dto_lsb = 0x07; |
| 824 | unsigned char data; |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 825 | #define PROBE_BUFFER_SIZE 8 |
| 826 | unsigned char buf[PROBE_BUFFER_SIZE]; |
| 827 | int i; |
| 828 | |
| 829 | /* rule out tda9887, which would return the same byte repeatedly */ |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 830 | tuner_i2c_xfer_send_recv(&i2c_props, |
| 831 | soft_reset, 1, buf, PROBE_BUFFER_SIZE); |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 832 | for (i = 1; i < PROBE_BUFFER_SIZE; i++) { |
Michael Krufky | bbe1e0b | 2007-11-05 09:54:42 -0300 | [diff] [blame] | 833 | if (buf[i] != buf[0]) |
| 834 | break; |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* all bytes are equal, not a tda829x - probably a tda9887 */ |
| 838 | if (i == PROBE_BUFFER_SIZE) |
| 839 | return -ENODEV; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 840 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 841 | if ((tda8290_probe(&i2c_props) == 0) || |
| 842 | (tda8295_probe(&i2c_props) == 0)) |
| 843 | return 0; |
| 844 | |
| 845 | /* fall back to old probing method */ |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 846 | tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2); |
| 847 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 848 | tuner_i2c_xfer_send_recv(&i2c_props, &addr_dto_lsb, 1, &data, 1); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 849 | if (data == 0) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 850 | tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2); |
| 851 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 852 | tuner_i2c_xfer_send_recv(&i2c_props, |
| 853 | &addr_dto_lsb, 1, &data, 1); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 854 | if (data == 0x7b) { |
| 855 | return 0; |
| 856 | } |
| 857 | } |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 858 | tuner_i2c_xfer_send(&i2c_props, restore_9886, 3); |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 859 | return -ENODEV; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 860 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 861 | EXPORT_SYMBOL_GPL(tda829x_probe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 862 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 863 | MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 864 | MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky"); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 865 | MODULE_LICENSE("GPL"); |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* |
| 868 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 869 | * --------------------------------------------------------------------------- |
| 870 | * Local variables: |
| 871 | * c-basic-offset: 8 |
| 872 | * End: |
| 873 | */ |