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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/delay.h> |
Michael Krufky | ffbb807 | 2007-08-21 01:14:12 -0300 | [diff] [blame] | 25 | #include <linux/videodev.h> |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 26 | #include "tda8290.h" |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 27 | #include "tda827x.h" |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 28 | #include "tda18271.h" |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 29 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 30 | static int tuner_debug; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 31 | module_param_named(debug, tuner_debug, int, 0644); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 32 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); |
| 33 | |
| 34 | #define PREFIX "tda8290 " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* ---------------------------------------------------------------------- */ |
| 37 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 38 | struct tda8290_priv { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 39 | struct tuner_i2c_props i2c_props; |
| 40 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 41 | unsigned char tda8290_easy_mode; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 42 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 43 | unsigned char tda827x_addr; |
| 44 | unsigned char tda827x_ver; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 45 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 46 | struct tda827x_config cfg; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 47 | }; |
| 48 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 49 | /*---------------------------------------------------------------------*/ |
| 50 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 51 | static void tda8290_i2c_bridge(struct tuner *t, int close) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 52 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 53 | struct tda8290_priv *priv = t->priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 54 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 55 | unsigned char enable[2] = { 0x21, 0xC0 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 56 | unsigned char disable[2] = { 0x21, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 57 | unsigned char *msg; |
| 58 | if(close) { |
| 59 | msg = enable; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 60 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 61 | /* let the bridge stabilize */ |
| 62 | msleep(20); |
| 63 | } else { |
| 64 | msg = disable; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 65 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 69 | static void tda8295_i2c_bridge(struct tuner *t, int close) |
| 70 | { |
| 71 | struct tda8290_priv *priv = t->priv; |
| 72 | |
| 73 | unsigned char enable[2] = { 0x45, 0xc1 }; |
| 74 | unsigned char disable[2] = { 0x46, 0x00 }; |
| 75 | unsigned char buf[3] = { 0x45, 0x01, 0x00 }; |
| 76 | unsigned char *msg; |
| 77 | if (close) { |
| 78 | msg = enable; |
| 79 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
| 80 | /* let the bridge stabilize */ |
| 81 | msleep(20); |
| 82 | } else { |
| 83 | msg = disable; |
| 84 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 1); |
| 85 | tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1); |
| 86 | |
| 87 | buf[2] = msg[1]; |
| 88 | buf[2] &= ~0x04; |
| 89 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 3); |
| 90 | msleep(5); |
| 91 | |
| 92 | msg[1] |= 0x04; |
| 93 | tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); |
| 94 | } |
| 95 | } |
| 96 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 97 | /*---------------------------------------------------------------------*/ |
| 98 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 99 | static void set_audio(struct tuner *t) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 100 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 101 | struct tda8290_priv *priv = t->priv; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 102 | char* mode; |
| 103 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 104 | priv->cfg.tda827x_lpsel = 0; |
| 105 | if (t->std & V4L2_STD_MN) { |
| 106 | priv->cfg.sgIF = 92; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 107 | priv->tda8290_easy_mode = 0x01; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 108 | priv->cfg.tda827x_lpsel = 1; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 109 | mode = "MN"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 110 | } else if (t->std & V4L2_STD_B) { |
| 111 | priv->cfg.sgIF = 108; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 112 | priv->tda8290_easy_mode = 0x02; |
| 113 | mode = "B"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 114 | } else if (t->std & V4L2_STD_GH) { |
| 115 | priv->cfg.sgIF = 124; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 116 | priv->tda8290_easy_mode = 0x04; |
| 117 | mode = "GH"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 118 | } else if (t->std & V4L2_STD_PAL_I) { |
| 119 | priv->cfg.sgIF = 124; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 120 | priv->tda8290_easy_mode = 0x08; |
| 121 | mode = "I"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 122 | } else if (t->std & V4L2_STD_DK) { |
| 123 | priv->cfg.sgIF = 124; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 124 | priv->tda8290_easy_mode = 0x10; |
| 125 | mode = "DK"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 126 | } else if (t->std & V4L2_STD_SECAM_L) { |
| 127 | priv->cfg.sgIF = 124; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 128 | priv->tda8290_easy_mode = 0x20; |
| 129 | mode = "L"; |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 130 | } else if (t->std & V4L2_STD_SECAM_LC) { |
| 131 | priv->cfg.sgIF = 20; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 132 | priv->tda8290_easy_mode = 0x40; |
| 133 | mode = "LC"; |
| 134 | } else { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 135 | priv->cfg.sgIF = 124; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 136 | priv->tda8290_easy_mode = 0x10; |
| 137 | mode = "xx"; |
| 138 | } |
| 139 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 140 | if (t->mode == V4L2_TUNER_RADIO) |
| 141 | priv->cfg.sgIF = 88; /* if frequency is 5.5 MHz */ |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 142 | |
| 143 | tuner_dbg("setting tda8290 to system %s\n", mode); |
| 144 | } |
| 145 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 146 | static void tda8290_set_freq(struct tuner *t, unsigned int freq) |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 147 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 148 | struct tda8290_priv *priv = t->priv; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 149 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 150 | unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 151 | unsigned char expert_mode[] = { 0x01, 0x80 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 152 | unsigned char agc_out_on[] = { 0x02, 0x00 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 153 | unsigned char gainset_off[] = { 0x28, 0x14 }; |
| 154 | unsigned char if_agc_spd[] = { 0x0f, 0x88 }; |
| 155 | unsigned char adc_head_6[] = { 0x05, 0x04 }; |
| 156 | unsigned char adc_head_9[] = { 0x05, 0x02 }; |
| 157 | unsigned char adc_head_12[] = { 0x05, 0x01 }; |
| 158 | unsigned char pll_bw_nom[] = { 0x0d, 0x47 }; |
| 159 | unsigned char pll_bw_low[] = { 0x0d, 0x27 }; |
| 160 | unsigned char gainset_2[] = { 0x28, 0x64 }; |
| 161 | unsigned char agc_rst_on[] = { 0x0e, 0x0b }; |
| 162 | unsigned char agc_rst_off[] = { 0x0e, 0x09 }; |
| 163 | unsigned char if_agc_set[] = { 0x0f, 0x81 }; |
| 164 | unsigned char addr_adc_sat = 0x1a; |
| 165 | unsigned char addr_agc_stat = 0x1d; |
| 166 | unsigned char addr_pll_stat = 0x1b; |
| 167 | unsigned char adc_sat, agc_stat, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 168 | pll_stat; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 169 | int i; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 170 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 171 | struct analog_parameters params = { |
| 172 | .frequency = freq, |
| 173 | .mode = t->mode, |
| 174 | .audmode = t->audmode, |
| 175 | .std = t->std |
| 176 | }; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 177 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 178 | set_audio(t); |
| 179 | |
| 180 | tuner_dbg("tda827xa config is 0x%02x\n", t->config); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 181 | tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2); |
| 182 | tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2); |
| 183 | tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 184 | msleep(1); |
| 185 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 186 | expert_mode[1] = priv->tda8290_easy_mode + 0x80; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 187 | tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2); |
| 188 | tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2); |
| 189 | tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2); |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 190 | if (priv->tda8290_easy_mode & 0x60) |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 191 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 192 | else |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 193 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2); |
| 194 | tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 195 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 196 | tda8290_i2c_bridge(t, 1); |
| 197 | |
| 198 | if (t->fe.ops.tuner_ops.set_analog_params) |
| 199 | t->fe.ops.tuner_ops.set_analog_params(&t->fe, ¶ms); |
| 200 | |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 201 | for (i = 0; i < 3; i++) { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 202 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); |
| 203 | tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 204 | if (pll_stat & 0x80) { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 205 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1); |
| 206 | tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1); |
| 207 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1); |
| 208 | tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 209 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); |
| 210 | break; |
| 211 | } else { |
| 212 | tuner_dbg("tda8290 not locked, no signal?\n"); |
| 213 | msleep(100); |
| 214 | } |
| 215 | } |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 216 | /* adjust headroom resp. gain */ |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 217 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { |
| 218 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", |
| 219 | agc_stat, adc_sat, pll_stat & 0x80); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 220 | tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 221 | msleep(100); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 222 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1); |
| 223 | tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1); |
| 224 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); |
| 225 | tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 226 | if ((agc_stat > 115) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 227 | tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", |
| 228 | agc_stat, pll_stat & 0x80); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 229 | if (priv->cfg.agcf) |
| 230 | priv->cfg.agcf(&t->fe); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 231 | msleep(100); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 232 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1); |
| 233 | tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1); |
| 234 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); |
| 235 | tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 236 | if((agc_stat > 115) || !(pll_stat & 0x80)) { |
| 237 | tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 238 | tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2); |
| 239 | tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 240 | msleep(100); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* l/ l' deadlock? */ |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 246 | if(priv->tda8290_easy_mode & 0x60) { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 247 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1); |
| 248 | tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1); |
| 249 | tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); |
| 250 | tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 251 | if ((adc_sat > 20) || !(pll_stat & 0x80)) { |
Hartmut Hackmann | 4ac95af | 2005-11-08 21:38:38 -0800 | [diff] [blame] | 252 | tuner_dbg("trying to resolve SECAM L deadlock\n"); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 253 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 254 | msleep(40); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 255 | tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 259 | tda8290_i2c_bridge(t, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 260 | tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 263 | /*---------------------------------------------------------------------*/ |
| 264 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 265 | static void tda8295_power(struct tuner *t, int enable) |
| 266 | { |
| 267 | struct tda8290_priv *priv = t->priv; |
| 268 | unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */ |
| 269 | |
| 270 | tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1); |
| 271 | tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1); |
| 272 | |
| 273 | if (enable) |
| 274 | buf[1] = 0x01; |
| 275 | else |
| 276 | buf[1] = 0x03; |
| 277 | |
| 278 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 279 | } |
| 280 | |
| 281 | static void tda8295_set_easy_mode(struct tuner *t, int enable) |
| 282 | { |
| 283 | struct tda8290_priv *priv = t->priv; |
| 284 | unsigned char buf[] = { 0x01, 0x00 }; |
| 285 | |
| 286 | tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1); |
| 287 | tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1); |
| 288 | |
| 289 | if (enable) |
| 290 | buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */ |
| 291 | else |
| 292 | buf[1] = 0x00; /* reset active bit */ |
| 293 | |
| 294 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 295 | } |
| 296 | |
| 297 | static void tda8295_set_video_std(struct tuner *t) |
| 298 | { |
| 299 | struct tda8290_priv *priv = t->priv; |
| 300 | unsigned char buf[] = { 0x00, priv->tda8290_easy_mode }; |
| 301 | |
| 302 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 303 | |
| 304 | tda8295_set_easy_mode(t, 1); |
| 305 | msleep(20); |
| 306 | tda8295_set_easy_mode(t, 0); |
| 307 | } |
| 308 | |
| 309 | /*---------------------------------------------------------------------*/ |
| 310 | |
| 311 | static void tda8295_agc1_out(struct tuner *t, int enable) |
| 312 | { |
| 313 | struct tda8290_priv *priv = t->priv; |
| 314 | unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */ |
| 315 | |
| 316 | tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1); |
| 317 | tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1); |
| 318 | |
| 319 | if (enable) |
| 320 | buf[1] &= ~0x40; |
| 321 | else |
| 322 | buf[1] |= 0x40; |
| 323 | |
| 324 | tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); |
| 325 | } |
| 326 | |
| 327 | static void tda8295_agc2_out(struct tuner *t, int enable) |
| 328 | { |
| 329 | struct tda8290_priv *priv = t->priv; |
| 330 | unsigned char set_gpio_cf[] = { 0x44, 0x00 }; |
| 331 | unsigned char set_gpio_val[] = { 0x46, 0x00 }; |
| 332 | |
| 333 | tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1); |
| 334 | tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1); |
| 335 | tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1); |
| 336 | tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1); |
| 337 | |
| 338 | set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */ |
| 339 | |
| 340 | if (enable) { |
| 341 | set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */ |
| 342 | set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */ |
| 343 | } |
| 344 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2); |
| 345 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2); |
| 346 | } |
| 347 | |
| 348 | static int tda8295_has_signal(struct tuner *t) |
| 349 | { |
| 350 | struct tda8290_priv *priv = t->priv; |
| 351 | |
| 352 | unsigned char hvpll_stat = 0x26; |
| 353 | unsigned char ret; |
| 354 | |
| 355 | tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1); |
| 356 | tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1); |
| 357 | return (ret & 0x01) ? 65535 : 0; |
| 358 | } |
| 359 | |
| 360 | /*---------------------------------------------------------------------*/ |
| 361 | |
| 362 | static void tda8295_set_freq(struct tuner *t, unsigned int freq) |
| 363 | { |
| 364 | struct tda8290_priv *priv = t->priv; |
| 365 | u16 ifc; |
| 366 | |
| 367 | unsigned char blanking_mode[] = { 0x1d, 0x00 }; |
| 368 | |
| 369 | struct analog_parameters params = { |
| 370 | .frequency = freq, |
| 371 | .mode = t->mode, |
| 372 | .audmode = t->audmode, |
| 373 | .std = t->std |
| 374 | }; |
| 375 | |
| 376 | set_audio(t); |
| 377 | |
| 378 | ifc = priv->cfg.sgIF; /* FIXME */ |
| 379 | |
| 380 | tuner_dbg("%s: ifc = %u, freq = %d\n", __FUNCTION__, ifc, freq); |
| 381 | |
| 382 | tda8295_power(t, 1); |
| 383 | tda8295_agc1_out(t, 1); |
| 384 | |
| 385 | tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1); |
| 386 | tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1); |
| 387 | |
| 388 | tda8295_set_video_std(t); |
| 389 | |
| 390 | blanking_mode[1] = 0x03; |
| 391 | tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2); |
| 392 | msleep(20); |
| 393 | |
| 394 | tda8295_i2c_bridge(t, 1); |
| 395 | |
| 396 | if (t->fe.ops.tuner_ops.set_analog_params) |
| 397 | t->fe.ops.tuner_ops.set_analog_params(&t->fe, ¶ms); |
| 398 | |
| 399 | if (priv->cfg.agcf) |
| 400 | priv->cfg.agcf(&t->fe); |
| 401 | |
| 402 | if (tda8295_has_signal(t)) |
| 403 | tuner_dbg("tda8295 is locked\n"); |
| 404 | else |
| 405 | tuner_dbg("tda8295 not locked, no signal?\n"); |
| 406 | |
| 407 | tda8295_i2c_bridge(t, 0); |
| 408 | } |
| 409 | |
| 410 | /*---------------------------------------------------------------------*/ |
| 411 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 412 | static int tda8290_has_signal(struct tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 414 | struct tda8290_priv *priv = t->priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | unsigned char i2c_get_afc[1] = { 0x1B }; |
| 417 | unsigned char afc = 0; |
| 418 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 419 | tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); |
| 420 | tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 421 | return (afc & 0x80)? 65535:0; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 422 | } |
| 423 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 424 | /*---------------------------------------------------------------------*/ |
| 425 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 426 | static void tda8290_standby(struct tuner *t) |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 427 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 428 | struct tda8290_priv *priv = t->priv; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 429 | unsigned char cb1[] = { 0x30, 0xD0 }; |
| 430 | unsigned char tda8290_standby[] = { 0x00, 0x02 }; |
Hartmut Hackmann | 0157a9c | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 431 | unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 432 | 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] | 433 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 434 | tda8290_i2c_bridge(t, 1); |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 435 | if (priv->tda827x_ver != 0) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 436 | cb1[1] = 0x90; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 437 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 438 | tda8290_i2c_bridge(t, 0); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 439 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); |
| 440 | tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 443 | static void tda8295_standby(struct tuner *t) |
| 444 | { |
| 445 | tda8295_agc1_out(t, 0); /* Put AGC in tri-state */ |
| 446 | |
| 447 | tda8295_power(t, 0); |
| 448 | } |
| 449 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 450 | static void tda8290_init_if(struct tuner *t) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 451 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 452 | struct tda8290_priv *priv = t->priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 453 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 454 | unsigned char set_VS[] = { 0x30, 0x6F }; |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 455 | unsigned char set_GP00_CF[] = { 0x20, 0x01 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 456 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
| 457 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 458 | if ((t->config == 1) || (t->config == 2)) |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 459 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); |
Hartmut Hackmann | 58ef4f9 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 460 | else |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 461 | tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); |
| 462 | tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 465 | static void tda8295_init_if(struct tuner *t) |
| 466 | { |
| 467 | struct tda8290_priv *priv = t->priv; |
| 468 | |
| 469 | static unsigned char set_adc_ctl[] = { 0x33, 0x14 }; |
| 470 | static unsigned char set_adc_ctl2[] = { 0x34, 0x00 }; |
| 471 | static unsigned char set_pll_reg6[] = { 0x3e, 0x63 }; |
| 472 | static unsigned char set_pll_reg0[] = { 0x38, 0x23 }; |
| 473 | static unsigned char set_pll_reg7[] = { 0x3f, 0x01 }; |
| 474 | static unsigned char set_pll_reg10[] = { 0x42, 0x61 }; |
| 475 | static unsigned char set_gpio_reg0[] = { 0x44, 0x0b }; |
| 476 | |
| 477 | tda8295_power(t, 1); |
| 478 | |
| 479 | tda8295_set_easy_mode(t, 0); |
| 480 | tda8295_set_video_std(t); |
| 481 | |
| 482 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2); |
| 483 | tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2); |
| 484 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2); |
| 485 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2); |
| 486 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2); |
| 487 | tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2); |
| 488 | tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2); |
| 489 | |
| 490 | tda8295_agc1_out(t, 0); |
| 491 | tda8295_agc2_out(t, 0); |
| 492 | } |
| 493 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 494 | static void tda8290_init_tuner(struct tuner *t) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 495 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 496 | struct tda8290_priv *priv = t->priv; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 497 | unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 498 | 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 499 | unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, |
Nickolay V. Shmyrev | 9a741ec | 2005-11-08 21:37:50 -0800 | [diff] [blame] | 500 | 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 501 | struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, |
Ricardo Cerqueira | c2f6f9d | 2005-11-08 21:37:51 -0800 | [diff] [blame] | 502 | .buf=tda8275_init, .len = 14}; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 503 | if (priv->tda827x_ver != 0) |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 504 | msg.buf = tda8275a_init; |
| 505 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 506 | tda8290_i2c_bridge(t, 1); |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 507 | i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 508 | tda8290_i2c_bridge(t, 0); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /*---------------------------------------------------------------------*/ |
| 512 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 513 | static void tda829x_release(struct tuner *t) |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 514 | { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 515 | if (t->fe.ops.tuner_ops.release) |
| 516 | t->fe.ops.tuner_ops.release(&t->fe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 517 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 518 | kfree(t->priv); |
| 519 | t->priv = NULL; |
Michael Krufky | 024cf53 | 2007-06-04 15:20:11 -0300 | [diff] [blame] | 520 | } |
| 521 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 522 | static struct tuner_operations tda8290_tuner_ops = { |
| 523 | .set_tv_freq = tda8290_set_freq, |
| 524 | .set_radio_freq = tda8290_set_freq, |
| 525 | .has_signal = tda8290_has_signal, |
| 526 | .standby = tda8290_standby, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 527 | .release = tda829x_release, |
| 528 | }; |
| 529 | |
| 530 | static struct tuner_operations tda8295_tuner_ops = { |
| 531 | .set_tv_freq = tda8295_set_freq, |
| 532 | .set_radio_freq = tda8295_set_freq, |
| 533 | .has_signal = tda8295_has_signal, |
| 534 | .standby = tda8295_standby, |
| 535 | .release = tda829x_release, |
Michael Krufky | 7fd8b26 | 2007-06-06 16:15:15 -0300 | [diff] [blame] | 536 | }; |
| 537 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 538 | int tda8290_attach(struct tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 540 | struct tda8290_priv *priv = NULL; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 541 | u8 data; |
| 542 | int i, ret, tuners_found; |
| 543 | u32 tuner_addrs; |
| 544 | struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 546 | priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); |
| 547 | if (priv == NULL) |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 548 | return -ENOMEM; |
| 549 | t->priv = priv; |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 550 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 551 | priv->i2c_props.addr = t->i2c.addr; |
| 552 | priv->i2c_props.adap = t->i2c.adapter; |
| 553 | priv->cfg.config = &t->config; |
| 554 | priv->cfg.tuner_callback = t->tuner_callback; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 555 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 556 | tda8290_i2c_bridge(t, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 557 | /* probe for tuner chip */ |
| 558 | tuners_found = 0; |
| 559 | tuner_addrs = 0; |
| 560 | for (i=0x60; i<= 0x63; i++) { |
| 561 | msg.addr = i; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 562 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 563 | if (ret == 1) { |
| 564 | tuners_found++; |
| 565 | tuner_addrs = (tuner_addrs << 8) + i; |
| 566 | } |
| 567 | } |
| 568 | /* if there is more than one tuner, we expect the right one is |
| 569 | behind the bridge and we choose the highest address that doesn't |
| 570 | give a response now |
| 571 | */ |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 572 | tda8290_i2c_bridge(t, 0); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 573 | if(tuners_found > 1) |
| 574 | for (i = 0; i < tuners_found; i++) { |
| 575 | msg.addr = tuner_addrs & 0xff; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 576 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 577 | if(ret == 1) |
| 578 | tuner_addrs = tuner_addrs >> 8; |
| 579 | else |
| 580 | break; |
| 581 | } |
| 582 | if (tuner_addrs == 0) { |
| 583 | tuner_addrs = 0x61; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 584 | tuner_info("could not clearly identify tuner address, defaulting to %x\n", |
Nickolay V. Shmyrev | 01cb963 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 585 | tuner_addrs); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 586 | } else { |
| 587 | tuner_addrs = tuner_addrs & 0xff; |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 588 | tuner_info("setting tuner address to %x\n", tuner_addrs); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 589 | } |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 590 | priv->tda827x_addr = tuner_addrs; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 591 | msg.addr = tuner_addrs; |
| 592 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 593 | tda8290_i2c_bridge(t, 1); |
| 594 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 595 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 596 | if( ret != 1) |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 597 | tuner_warn("TDA827x access failed!\n"); |
| 598 | |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 599 | if ((data & 0x3c) == 0) { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 600 | strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name)); |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 601 | priv->tda827x_ver = 0; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 602 | } else { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 603 | strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name)); |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 604 | priv->tda827x_ver = 2; |
Hartmut Hackmann | de48eeb | 2005-11-08 21:37:48 -0800 | [diff] [blame] | 605 | } |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 606 | tda827x_attach(&t->fe, priv->tda827x_addr, |
| 607 | priv->i2c_props.adap, &priv->cfg); |
Michael Krufky | 7fd8b26 | 2007-06-06 16:15:15 -0300 | [diff] [blame] | 608 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 609 | /* FIXME: tda827x module doesn't probe the tuner until |
| 610 | * tda827x_initial_sleep is called |
| 611 | */ |
| 612 | if (t->fe.ops.tuner_ops.sleep) |
| 613 | t->fe.ops.tuner_ops.sleep(&t->fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 615 | memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations)); |
| 616 | |
| 617 | tuner_info("type set to %s\n", t->i2c.name); |
| 618 | |
| 619 | priv->cfg.tda827x_lpsel = 0; |
| 620 | t->mode = V4L2_TUNER_ANALOG_TV; |
| 621 | |
| 622 | tda8290_init_tuner(t); |
| 623 | tda8290_init_if(t); |
| 624 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 626 | EXPORT_SYMBOL_GPL(tda8290_attach); |
| 627 | |
| 628 | int tda8295_attach(struct tuner *t) |
| 629 | { |
| 630 | struct tda8290_priv *priv = NULL; |
| 631 | u8 data; |
| 632 | int i, ret, tuners_found; |
| 633 | u32 tuner_addrs; |
| 634 | struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 }; |
| 635 | |
| 636 | priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); |
| 637 | if (priv == NULL) |
| 638 | return -ENOMEM; |
| 639 | t->priv = priv; |
| 640 | |
| 641 | priv->i2c_props.addr = t->i2c.addr; |
| 642 | priv->i2c_props.adap = t->i2c.adapter; |
| 643 | |
| 644 | tda8295_i2c_bridge(t, 1); |
| 645 | /* probe for tuner chip */ |
| 646 | tuners_found = 0; |
| 647 | tuner_addrs = 0; |
| 648 | for (i = 0x60; i <= 0x63; i++) { |
| 649 | msg.addr = i; |
| 650 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 651 | if (ret == 1) { |
| 652 | tuners_found++; |
| 653 | tuner_addrs = (tuner_addrs << 8) + i; |
| 654 | } |
| 655 | } |
| 656 | /* if there is more than one tuner, we expect the right one is |
| 657 | behind the bridge and we choose the highest address that doesn't |
| 658 | give a response now |
| 659 | */ |
| 660 | tda8295_i2c_bridge(t, 0); |
| 661 | if (tuners_found > 1) |
| 662 | for (i = 0; i < tuners_found; i++) { |
| 663 | msg.addr = tuner_addrs & 0xff; |
| 664 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 665 | if (ret == 1) |
| 666 | tuner_addrs = tuner_addrs >> 8; |
| 667 | else |
| 668 | break; |
| 669 | } |
| 670 | if (tuner_addrs == 0) { |
| 671 | tuner_addrs = 0x60; |
| 672 | tuner_info("could not clearly identify tuner address, " |
| 673 | "defaulting to %x\n", tuner_addrs); |
| 674 | } else { |
| 675 | tuner_addrs = tuner_addrs & 0xff; |
| 676 | tuner_info("setting tuner address to %x\n", tuner_addrs); |
| 677 | } |
| 678 | priv->tda827x_addr = tuner_addrs; |
| 679 | msg.addr = tuner_addrs; |
| 680 | |
| 681 | tda8295_i2c_bridge(t, 1); |
| 682 | ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); |
| 683 | tda8295_i2c_bridge(t, 0); |
| 684 | if (ret != 1) |
| 685 | tuner_warn("TDA827x access failed!\n"); |
| 686 | if ((data & 0x3c) == 0) { |
| 687 | strlcpy(t->i2c.name, "tda8295+18271", sizeof(t->i2c.name)); |
| 688 | tda18271_attach(&t->fe, priv->tda827x_addr, |
| 689 | priv->i2c_props.adap); |
| 690 | priv->tda827x_ver = 4; |
| 691 | } else { |
| 692 | strlcpy(t->i2c.name, "tda8295+75a", sizeof(t->i2c.name)); |
| 693 | tda827x_attach(&t->fe, priv->tda827x_addr, |
| 694 | priv->i2c_props.adap, &priv->cfg); |
| 695 | |
| 696 | /* FIXME: tda827x module doesn't probe the tuner until |
| 697 | * tda827x_initial_sleep is called |
| 698 | */ |
| 699 | if (t->fe.ops.tuner_ops.sleep) |
| 700 | t->fe.ops.tuner_ops.sleep(&t->fe); |
| 701 | priv->tda827x_ver = 2; |
| 702 | } |
| 703 | priv->tda827x_ver |= 1; /* signifies 8295 vs 8290 */ |
| 704 | tuner_info("type set to %s\n", t->i2c.name); |
| 705 | |
| 706 | memcpy(&t->ops, &tda8295_tuner_ops, sizeof(struct tuner_operations)); |
| 707 | |
| 708 | priv->cfg.tda827x_lpsel = 0; |
| 709 | t->mode = V4L2_TUNER_ANALOG_TV; |
| 710 | |
| 711 | tda8295_init_if(t); |
| 712 | return 0; |
| 713 | } |
| 714 | EXPORT_SYMBOL_GPL(tda8295_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 716 | int tda8290_probe(struct tuner *t) |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 717 | { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 718 | struct tuner_i2c_props i2c_props = { |
Michael Krufky | 746d9732 | 2007-08-25 19:08:45 -0300 | [diff] [blame] | 719 | .adap = t->i2c.adapter, |
| 720 | .addr = t->i2c.addr |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 721 | }; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 722 | |
Hartmut Hackmann | 44fd06f | 2006-02-27 00:09:11 -0300 | [diff] [blame] | 723 | unsigned char soft_reset[] = { 0x00, 0x00 }; |
| 724 | unsigned char easy_mode_b[] = { 0x01, 0x02 }; |
| 725 | unsigned char easy_mode_g[] = { 0x01, 0x04 }; |
| 726 | unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 }; |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 727 | unsigned char addr_dto_lsb = 0x07; |
| 728 | unsigned char data; |
| 729 | |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 730 | tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2); |
| 731 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
| 732 | tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1); |
| 733 | tuner_i2c_xfer_recv(&i2c_props, &data, 1); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 734 | if (data == 0) { |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 735 | tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2); |
| 736 | tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); |
| 737 | tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1); |
| 738 | tuner_i2c_xfer_recv(&i2c_props, &data, 1); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 739 | if (data == 0x7b) { |
| 740 | return 0; |
| 741 | } |
| 742 | } |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 743 | tuner_i2c_xfer_send(&i2c_props, restore_9886, 3); |
Hartmut Hackmann | 9573603 | 2005-11-08 21:38:00 -0800 | [diff] [blame] | 744 | return -1; |
| 745 | } |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 746 | EXPORT_SYMBOL_GPL(tda8290_probe); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 747 | |
| 748 | MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame^] | 749 | MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky"); |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 750 | MODULE_LICENSE("GPL"); |
| 751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | /* |
| 753 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 754 | * --------------------------------------------------------------------------- |
| 755 | * Local variables: |
| 756 | * c-basic-offset: 8 |
| 757 | * End: |
| 758 | */ |