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 | |
Mauro Carvalho Chehab | ecb71d2 | 2011-01-14 12:03:03 -0300 | [diff] [blame] | 235 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 236 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 237 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 238 | if (fe->ops.tuner_ops.set_analog_params) |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 239 | fe->ops.tuner_ops.set_analog_params(fe, params); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 240 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 241 | for (i = 0; i < 3; i++) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 242 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 243 | &addr_pll_stat, 1, &pll_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 244 | if (pll_stat & 0x80) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 245 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 246 | &addr_adc_sat, 1, |
| 247 | &adc_sat, 1); |
| 248 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 249 | &addr_agc_stat, 1, |
| 250 | &agc_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 251 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); |
| 252 | break; |
| 253 | } else { |
| 254 | tuner_dbg("tda8290 not locked, no signal?\n"); |
| 255 | msleep(100); |
| 256 | } |
| 257 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 258 | /* adjust headroom resp. gain */ |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 259 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { |
| 260 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", |
| 261 | agc_stat, adc_sat, pll_stat & 0x80); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 262 | tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 263 | msleep(100); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 264 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 265 | &addr_agc_stat, 1, &agc_stat, 1); |
| 266 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 267 | &addr_pll_stat, 1, &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 268 | if ((agc_stat > 115) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 269 | tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", |
| 270 | agc_stat, pll_stat & 0x80); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 271 | if (priv->cfg.agcf) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 272 | priv->cfg.agcf(fe); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 273 | msleep(100); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 274 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 275 | &addr_agc_stat, 1, |
| 276 | &agc_stat, 1); |
| 277 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 278 | &addr_pll_stat, 1, |
| 279 | &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 280 | if((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 281 | tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 282 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2); |
| 283 | tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 284 | msleep(100); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /* l/ l' deadlock? */ |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 290 | if(priv->tda8290_easy_mode & 0x60) { |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 291 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 292 | &addr_adc_sat, 1, |
| 293 | &adc_sat, 1); |
| 294 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 295 | &addr_pll_stat, 1, |
| 296 | &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 297 | if ((adc_sat > 20) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 298 | tuner_dbg("trying to resolve SECAM L deadlock\n"); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 299 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 300 | msleep(40); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 301 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 305 | tda8290_i2c_bridge(fe, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 306 | tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 309 | /*---------------------------------------------------------------------*/ |
| 310 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 311 | static void tda8295_power(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 312 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 313 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 314 | unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */ |
| 315 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 316 | 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] | 317 | |
| 318 | if (enable) |
| 319 | buf[1] = 0x01; |
| 320 | else |
| 321 | buf[1] = 0x03; |
| 322 | |
| 323 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 324 | } |
| 325 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 326 | static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 327 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 328 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 329 | unsigned char buf[] = { 0x01, 0x00 }; |
| 330 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 331 | 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] | 332 | |
| 333 | if (enable) |
| 334 | buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */ |
| 335 | else |
| 336 | buf[1] = 0x00; /* reset active bit */ |
| 337 | |
| 338 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 339 | } |
| 340 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 341 | static void tda8295_set_video_std(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 342 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 343 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 344 | unsigned char buf[] = { 0x00, priv->tda8290_easy_mode }; |
| 345 | |
| 346 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 347 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 348 | tda8295_set_easy_mode(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 349 | msleep(20); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 350 | tda8295_set_easy_mode(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /*---------------------------------------------------------------------*/ |
| 354 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 355 | static void tda8295_agc1_out(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 356 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 357 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 358 | unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */ |
| 359 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 360 | 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] | 361 | |
| 362 | if (enable) |
| 363 | buf[1] &= ~0x40; |
| 364 | else |
| 365 | buf[1] |= 0x40; |
| 366 | |
| 367 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 368 | } |
| 369 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 370 | static void tda8295_agc2_out(struct dvb_frontend *fe, int enable) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 371 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 372 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 373 | unsigned char set_gpio_cf[] = { 0x44, 0x00 }; |
| 374 | unsigned char set_gpio_val[] = { 0x46, 0x00 }; |
| 375 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 376 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 377 | &set_gpio_cf[0], 1, &set_gpio_cf[1], 1); |
| 378 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 379 | &set_gpio_val[0], 1, &set_gpio_val[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 380 | |
| 381 | set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */ |
| 382 | |
| 383 | if (enable) { |
| 384 | set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */ |
| 385 | set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */ |
| 386 | } |
| 387 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2); |
| 388 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2); |
| 389 | } |
| 390 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 391 | static int tda8295_has_signal(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 392 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 393 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 394 | |
| 395 | unsigned char hvpll_stat = 0x26; |
| 396 | unsigned char ret; |
| 397 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 398 | 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] | 399 | return (ret & 0x01) ? 65535 : 0; |
| 400 | } |
| 401 | |
| 402 | /*---------------------------------------------------------------------*/ |
| 403 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 404 | static void tda8295_set_params(struct dvb_frontend *fe, |
| 405 | struct analog_parameters *params) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 406 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 407 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 408 | |
| 409 | unsigned char blanking_mode[] = { 0x1d, 0x00 }; |
| 410 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 411 | set_audio(fe, params); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 412 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 413 | tuner_dbg("%s: freq = %d\n", __func__, params->frequency); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 414 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 415 | tda8295_power(fe, 1); |
| 416 | tda8295_agc1_out(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 417 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 418 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 419 | &blanking_mode[0], 1, &blanking_mode[1], 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 420 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 421 | tda8295_set_video_std(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 422 | |
| 423 | blanking_mode[1] = 0x03; |
| 424 | tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2); |
| 425 | msleep(20); |
| 426 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 427 | tda8295_i2c_bridge(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 428 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 429 | if (fe->ops.tuner_ops.set_analog_params) |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 430 | fe->ops.tuner_ops.set_analog_params(fe, params); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 431 | |
| 432 | if (priv->cfg.agcf) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 433 | priv->cfg.agcf(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 434 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 435 | if (tda8295_has_signal(fe)) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 436 | tuner_dbg("tda8295 is locked\n"); |
| 437 | else |
| 438 | tuner_dbg("tda8295 not locked, no signal?\n"); |
| 439 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 440 | tda8295_i2c_bridge(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /*---------------------------------------------------------------------*/ |
| 444 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 445 | static int tda8290_has_signal(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 447 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | unsigned char i2c_get_afc[1] = { 0x1B }; |
| 450 | unsigned char afc = 0; |
| 451 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 452 | tuner_i2c_xfer_send_recv(&priv->i2c_props, |
| 453 | i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 454 | return (afc & 0x80)? 65535:0; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 455 | } |
| 456 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 457 | /*---------------------------------------------------------------------*/ |
| 458 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 459 | static void tda8290_standby(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 460 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 461 | struct tda8290_priv *priv = fe->analog_demod_priv; |
| 462 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 463 | unsigned char cb1[] = { 0x30, 0xD0 }; |
| 464 | unsigned char tda8290_standby[] = { 0x00, 0x02 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 465 | unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 466 | 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] | 467 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 468 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 469 | if (priv->ver & TDA8275A) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 470 | cb1[1] = 0x90; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 471 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 472 | tda8290_i2c_bridge(fe, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 473 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); |
| 474 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 477 | static void tda8295_standby(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 478 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 479 | tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 480 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 481 | tda8295_power(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 482 | } |
| 483 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 484 | static void tda8290_init_if(struct dvb_frontend *fe) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 485 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 486 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 487 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 488 | unsigned char set_VS[] = { 0x30, 0x6F }; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 489 | unsigned char set_GP00_CF[] = { 0x20, 0x01 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 490 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
| 491 | |
Hartmut Hackmann | 7bff4b4 | 2008-04-22 14:46:08 -0300 | [diff] [blame] | 492 | if ((priv->cfg.config == 1) || (priv->cfg.config == 2)) |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 493 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 494 | else |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 495 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); |
| 496 | tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 499 | static void tda8295_init_if(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 500 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 501 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 502 | |
| 503 | static unsigned char set_adc_ctl[] = { 0x33, 0x14 }; |
| 504 | static unsigned char set_adc_ctl2[] = { 0x34, 0x00 }; |
| 505 | static unsigned char set_pll_reg6[] = { 0x3e, 0x63 }; |
| 506 | static unsigned char set_pll_reg0[] = { 0x38, 0x23 }; |
| 507 | static unsigned char set_pll_reg7[] = { 0x3f, 0x01 }; |
| 508 | static unsigned char set_pll_reg10[] = { 0x42, 0x61 }; |
| 509 | static unsigned char set_gpio_reg0[] = { 0x44, 0x0b }; |
| 510 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 511 | tda8295_power(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 512 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 513 | tda8295_set_easy_mode(fe, 0); |
| 514 | tda8295_set_video_std(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 515 | |
| 516 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2); |
| 517 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2); |
| 518 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2); |
| 519 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2); |
| 520 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2); |
| 521 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2); |
| 522 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2); |
| 523 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 524 | tda8295_agc1_out(fe, 0); |
| 525 | tda8295_agc2_out(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 526 | } |
| 527 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 528 | static void tda8290_init_tuner(struct dvb_frontend *fe) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 529 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 530 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 531 | unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 532 | 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 533 | unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 534 | 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 535 | struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, |
Ricardo Cerqueira | c2f6f9d | 2005-11-08 21:37:51 -0800 | [diff] [blame] | 536 | .buf=tda8275_init, .len = 14}; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 537 | if (priv->ver & TDA8275A) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 538 | msg.buf = tda8275a_init; |
| 539 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 540 | tda8290_i2c_bridge(fe, 1); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 541 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 542 | tda8290_i2c_bridge(fe, 0); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /*---------------------------------------------------------------------*/ |
| 546 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 547 | static void tda829x_release(struct dvb_frontend *fe) |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 548 | { |
Michael Krufky | a4f263b | 2008-01-06 15:52:56 -0300 | [diff] [blame] | 549 | struct tda8290_priv *priv = fe->analog_demod_priv; |
| 550 | |
Michael Krufky | 006ed1e | 2008-01-09 10:44:27 -0300 | [diff] [blame] | 551 | /* only try to release the tuner if we've |
| 552 | * attached it from within this module */ |
| 553 | if (priv->ver & (TDA18271 | TDA8275 | TDA8275A)) |
Michael Krufky | a4f263b | 2008-01-06 15:52:56 -0300 | [diff] [blame] | 554 | if (fe->ops.tuner_ops.release) |
| 555 | fe->ops.tuner_ops.release(fe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 556 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 557 | kfree(fe->analog_demod_priv); |
| 558 | fe->analog_demod_priv = NULL; |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 559 | } |
| 560 | |
Michael Krufky | f21e0d7 | 2008-01-02 03:01:54 -0300 | [diff] [blame] | 561 | static struct tda18271_config tda829x_tda18271_config = { |
| 562 | .gate = TDA18271_GATE_ANALOG, |
| 563 | }; |
| 564 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 565 | static int tda829x_find_tuner(struct dvb_frontend *fe) |
| 566 | { |
| 567 | struct tda8290_priv *priv = fe->analog_demod_priv; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 568 | struct analog_demod_ops *analog_ops = &fe->ops.analog_ops; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 569 | int i, ret, tuners_found; |
| 570 | u32 tuner_addrs; |
| 571 | u8 data; |
| 572 | struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 }; |
| 573 | |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 574 | if (!analog_ops->i2c_gate_ctrl) { |
| 575 | printk(KERN_ERR "tda8290: no gate control were provided!\n"); |
| 576 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 577 | return -EINVAL; |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 578 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 579 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 580 | analog_ops->i2c_gate_ctrl(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 581 | |
| 582 | /* probe for tuner chip */ |
| 583 | tuners_found = 0; |
| 584 | tuner_addrs = 0; |
| 585 | for (i = 0x60; i <= 0x63; i++) { |
| 586 | msg.addr = i; |
| 587 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 588 | if (ret == 1) { |
| 589 | tuners_found++; |
| 590 | tuner_addrs = (tuner_addrs << 8) + i; |
| 591 | } |
| 592 | } |
| 593 | /* if there is more than one tuner, we expect the right one is |
| 594 | behind the bridge and we choose the highest address that doesn't |
| 595 | give a response now |
| 596 | */ |
| 597 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 598 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 599 | |
| 600 | if (tuners_found > 1) |
| 601 | for (i = 0; i < tuners_found; i++) { |
| 602 | msg.addr = tuner_addrs & 0xff; |
| 603 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 604 | if (ret == 1) |
| 605 | tuner_addrs = tuner_addrs >> 8; |
| 606 | else |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | if (tuner_addrs == 0) { |
| 611 | tuner_addrs = 0x60; |
| 612 | tuner_info("could not clearly identify tuner address, " |
| 613 | "defaulting to %x\n", tuner_addrs); |
| 614 | } else { |
| 615 | tuner_addrs = tuner_addrs & 0xff; |
| 616 | tuner_info("setting tuner address to %x\n", tuner_addrs); |
| 617 | } |
| 618 | priv->tda827x_addr = tuner_addrs; |
| 619 | msg.addr = tuner_addrs; |
| 620 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 621 | analog_ops->i2c_gate_ctrl(fe, 1); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 622 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 623 | |
| 624 | if (ret != 1) { |
| 625 | tuner_warn("tuner access failed!\n"); |
Mauro Carvalho Chehab | 3106381 | 2009-02-08 08:42:29 -0300 | [diff] [blame] | 626 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 627 | return -EREMOTEIO; |
| 628 | } |
| 629 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 630 | if ((data == 0x83) || (data == 0x84)) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 631 | priv->ver |= TDA18271; |
Michael Krufky | adcc4b3 | 2009-03-04 19:42:06 -0300 | [diff] [blame] | 632 | tda829x_tda18271_config.config = priv->cfg.config; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 633 | dvb_attach(tda18271_attach, fe, priv->tda827x_addr, |
| 634 | priv->i2c_props.adap, &tda829x_tda18271_config); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 635 | } else { |
| 636 | if ((data & 0x3c) == 0) |
| 637 | priv->ver |= TDA8275; |
| 638 | else |
| 639 | priv->ver |= TDA8275A; |
| 640 | |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 641 | dvb_attach(tda827x_attach, fe, priv->tda827x_addr, |
| 642 | priv->i2c_props.adap, &priv->cfg); |
Hartmut Hackmann | 7bff4b4 | 2008-04-22 14:46:08 -0300 | [diff] [blame] | 643 | priv->cfg.switch_addr = priv->i2c_props.addr; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 644 | } |
Michael Krufky | 6881647 | 2007-12-08 16:25:41 -0300 | [diff] [blame] | 645 | if (fe->ops.tuner_ops.init) |
| 646 | fe->ops.tuner_ops.init(fe); |
Michael Krufky | 63c2548 | 2007-11-23 15:08:11 -0300 | [diff] [blame] | 647 | |
Michael Krufky | 6881647 | 2007-12-08 16:25:41 -0300 | [diff] [blame] | 648 | if (fe->ops.tuner_ops.sleep) |
| 649 | fe->ops.tuner_ops.sleep(fe); |
Michael Krufky | 63c2548 | 2007-11-23 15:08:11 -0300 | [diff] [blame] | 650 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 651 | analog_ops->i2c_gate_ctrl(fe, 0); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 652 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 653 | return 0; |
| 654 | } |
| 655 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 656 | static int tda8290_probe(struct tuner_i2c_props *i2c_props) |
| 657 | { |
| 658 | #define TDA8290_ID 0x89 |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 659 | u8 reg = 0x1f, id; |
| 660 | struct i2c_msg msg_read[] = { |
Jarod Wilson | 89a8969 | 2011-03-01 12:38:48 -0300 | [diff] [blame] | 661 | { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® }, |
| 662 | { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id }, |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 663 | }; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 664 | |
| 665 | /* detect tda8290 */ |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 666 | if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) { |
Jarod Wilson | 89a8969 | 2011-03-01 12:38:48 -0300 | [diff] [blame] | 667 | printk(KERN_WARNING "%s: couldn't read register 0x%02x\n", |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 668 | __func__, reg); |
| 669 | return -ENODEV; |
| 670 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 671 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 672 | if (id == TDA8290_ID) { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 673 | if (debug) |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 674 | printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n", |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 675 | __func__, i2c_adapter_id(i2c_props->adap), |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 676 | i2c_props->addr); |
| 677 | return 0; |
| 678 | } |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 679 | return -ENODEV; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static int tda8295_probe(struct tuner_i2c_props *i2c_props) |
| 683 | { |
| 684 | #define TDA8295_ID 0x8a |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 685 | #define TDA8295C2_ID 0x8b |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 686 | u8 reg = 0x2f, id; |
| 687 | struct i2c_msg msg_read[] = { |
Jarod Wilson | 89a8969 | 2011-03-01 12:38:48 -0300 | [diff] [blame] | 688 | { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® }, |
| 689 | { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id }, |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 690 | }; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 691 | |
Jarod Wilson | 89a8969 | 2011-03-01 12:38:48 -0300 | [diff] [blame] | 692 | /* detect tda8295 */ |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 693 | if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) { |
Jarod Wilson | 89a8969 | 2011-03-01 12:38:48 -0300 | [diff] [blame] | 694 | printk(KERN_WARNING "%s: couldn't read register 0x%02x\n", |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 695 | __func__, reg); |
| 696 | return -ENODEV; |
| 697 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 698 | |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 699 | if ((id & 0xfe) == TDA8295_ID) { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 700 | if (debug) |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 701 | printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n", |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 702 | __func__, (id == TDA8295_ID) ? |
Michael Krufky | 19f8a6c | 2009-12-31 04:32:29 -0300 | [diff] [blame] | 703 | "tda8295c1" : "tda8295c2", |
| 704 | i2c_adapter_id(i2c_props->adap), |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 705 | i2c_props->addr); |
| 706 | return 0; |
| 707 | } |
| 708 | |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 709 | return -ENODEV; |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 710 | } |
| 711 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 712 | static struct analog_demod_ops tda8290_ops = { |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 713 | .set_params = tda8290_set_params, |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 714 | .has_signal = tda8290_has_signal, |
| 715 | .standby = tda8290_standby, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 716 | .release = tda829x_release, |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 717 | .i2c_gate_ctrl = tda8290_i2c_bridge, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 718 | }; |
| 719 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 720 | static struct analog_demod_ops tda8295_ops = { |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 721 | .set_params = tda8295_set_params, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 722 | .has_signal = tda8295_has_signal, |
| 723 | .standby = tda8295_standby, |
| 724 | .release = tda829x_release, |
Michael Krufky | a72dd30 | 2007-10-24 09:30:17 -0300 | [diff] [blame] | 725 | .i2c_gate_ctrl = tda8295_i2c_bridge, |
Michael Krufky | 7fd8b26 | 2007-06-06 16:15:15 -0300 | [diff] [blame] | 726 | }; |
| 727 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 728 | struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe, |
| 729 | struct i2c_adapter *i2c_adap, u8 i2c_addr, |
| 730 | struct tda829x_config *cfg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 732 | struct tda8290_priv *priv = NULL; |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 733 | char *name; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 734 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 735 | priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); |
| 736 | if (priv == NULL) |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 737 | return NULL; |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 738 | fe->analog_demod_priv = priv; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 739 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 740 | priv->i2c_props.addr = i2c_addr; |
| 741 | priv->i2c_props.adap = i2c_adap; |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 742 | priv->i2c_props.name = "tda829x"; |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 743 | if (cfg) |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 744 | priv->cfg.config = cfg->lna_cfg; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 745 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 746 | if (tda8290_probe(&priv->i2c_props) == 0) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 747 | priv->ver = TDA8290; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 748 | memcpy(&fe->ops.analog_ops, &tda8290_ops, |
| 749 | sizeof(struct analog_demod_ops)); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 750 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 751 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 752 | if (tda8295_probe(&priv->i2c_props) == 0) { |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 753 | priv->ver = TDA8295; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 754 | memcpy(&fe->ops.analog_ops, &tda8295_ops, |
| 755 | sizeof(struct analog_demod_ops)); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 756 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 757 | |
Mauro Carvalho Chehab | 9d700a0 | 2011-01-13 14:01:39 -0300 | [diff] [blame] | 758 | if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) { |
| 759 | tda8295_power(fe, 1); |
| 760 | if (tda829x_find_tuner(fe) < 0) |
| 761 | goto fail; |
Mauro Carvalho Chehab | 47ab285 | 2011-01-13 12:02:00 -0300 | [diff] [blame] | 762 | } |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 763 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 764 | switch (priv->ver) { |
Michael Krufky | c907627 | 2007-12-24 04:36:14 -0300 | [diff] [blame] | 765 | case TDA8290: |
| 766 | name = "tda8290"; |
| 767 | break; |
| 768 | case TDA8295: |
| 769 | name = "tda8295"; |
| 770 | break; |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 771 | case TDA8290 | TDA8275: |
| 772 | name = "tda8290+75"; |
| 773 | break; |
| 774 | case TDA8295 | TDA8275: |
| 775 | name = "tda8295+75"; |
| 776 | break; |
| 777 | case TDA8290 | TDA8275A: |
| 778 | name = "tda8290+75a"; |
| 779 | break; |
| 780 | case TDA8295 | TDA8275A: |
| 781 | name = "tda8295+75a"; |
| 782 | break; |
| 783 | case TDA8290 | TDA18271: |
| 784 | name = "tda8290+18271"; |
| 785 | break; |
| 786 | case TDA8295 | TDA18271: |
| 787 | name = "tda8295+18271"; |
| 788 | break; |
| 789 | default: |
| 790 | goto fail; |
| 791 | } |
| 792 | tuner_info("type set to %s\n", name); |
| 793 | |
Michael Krufky | 0f2ce98 | 2008-01-21 10:55:37 -0300 | [diff] [blame] | 794 | fe->ops.analog_ops.info.name = name; |
| 795 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 796 | if (priv->ver & TDA8290) { |
Michael Krufky | 439b72b | 2009-01-05 18:25:04 -0300 | [diff] [blame] | 797 | if (priv->ver & (TDA8275 | TDA8275A)) |
| 798 | tda8290_init_tuner(fe); |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 799 | tda8290_init_if(fe); |
| 800 | } else if (priv->ver & TDA8295) |
| 801 | tda8295_init_if(fe); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 802 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 803 | return fe; |
Michael Krufky | fa746aee | 2007-12-09 05:16:10 -0300 | [diff] [blame] | 804 | |
| 805 | fail: |
Mauro Carvalho Chehab | 9d700a0 | 2011-01-13 14:01:39 -0300 | [diff] [blame] | 806 | memset(&fe->ops.analog_ops, 0, sizeof(struct analog_demod_ops)); |
| 807 | |
Michael Krufky | fa746aee | 2007-12-09 05:16:10 -0300 | [diff] [blame] | 808 | tda829x_release(fe); |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 809 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 811 | EXPORT_SYMBOL_GPL(tda829x_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 813 | int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr) |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 814 | { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 815 | struct tuner_i2c_props i2c_props = { |
Michael Krufky | ab16605 | 2007-12-09 02:26:48 -0300 | [diff] [blame] | 816 | .adap = i2c_adap, |
| 817 | .addr = i2c_addr, |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 818 | }; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 819 | |
Hartmut Hackmann | 44fd06f | 2006-02-27 00:09:11 -0300 | [diff] [blame] | 820 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 821 | unsigned char easy_mode_b[] = { 0x01, 0x02 }; |
| 822 | unsigned char easy_mode_g[] = { 0x01, 0x04 }; |
| 823 | unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 }; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 824 | unsigned char addr_dto_lsb = 0x07; |
| 825 | unsigned char data; |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 826 | #define PROBE_BUFFER_SIZE 8 |
| 827 | unsigned char buf[PROBE_BUFFER_SIZE]; |
| 828 | int i; |
| 829 | |
| 830 | /* rule out tda9887, which would return the same byte repeatedly */ |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 831 | tuner_i2c_xfer_send_recv(&i2c_props, |
| 832 | soft_reset, 1, buf, PROBE_BUFFER_SIZE); |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 833 | for (i = 1; i < PROBE_BUFFER_SIZE; i++) { |
Michael Krufky | bbe1e0b | 2007-11-05 09:54:42 -0300 | [diff] [blame] | 834 | if (buf[i] != buf[0]) |
| 835 | break; |
Michael Krufky | a818e1c | 2007-11-04 11:03:22 -0300 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | /* all bytes are equal, not a tda829x - probably a tda9887 */ |
| 839 | if (i == PROBE_BUFFER_SIZE) |
| 840 | return -ENODEV; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 841 | |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 842 | if ((tda8290_probe(&i2c_props) == 0) || |
| 843 | (tda8295_probe(&i2c_props) == 0)) |
| 844 | return 0; |
| 845 | |
| 846 | /* fall back to old probing method */ |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 847 | tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2); |
| 848 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 849 | 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] | 850 | if (data == 0) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 851 | tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2); |
| 852 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
Mauro Carvalho Chehab | 567aba0 | 2011-01-13 11:58:36 -0300 | [diff] [blame] | 853 | tuner_i2c_xfer_send_recv(&i2c_props, |
| 854 | &addr_dto_lsb, 1, &data, 1); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 855 | if (data == 0x7b) { |
| 856 | return 0; |
| 857 | } |
| 858 | } |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 859 | tuner_i2c_xfer_send(&i2c_props, restore_9886, 3); |
Michael Krufky | 1f3a4e32 | 2007-11-04 10:51:28 -0300 | [diff] [blame] | 860 | return -ENODEV; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 861 | } |
Michael Krufky | f1f3284 | 2007-11-03 22:14:54 -0300 | [diff] [blame] | 862 | EXPORT_SYMBOL_GPL(tda829x_probe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 863 | |
Michael Krufky | 8c125f2c | 2007-10-27 02:00:57 -0300 | [diff] [blame] | 864 | MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 865 | MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky"); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 866 | MODULE_LICENSE("GPL"); |
| 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* |
| 869 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 870 | * --------------------------------------------------------------------------- |
| 871 | * Local variables: |
| 872 | * c-basic-offset: 8 |
| 873 | * End: |
| 874 | */ |