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