Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview |
| 3 | * I2C address is allways 0xC0. |
| 4 | * |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 5 | * |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 6 | * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@infradead.org) |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 7 | * This code is placed under the terms of the GNU General Public License |
| 8 | * |
| 9 | * tea5767 autodetection thanks to Torsten Seeboth and Atsushi Nakagawa |
| 10 | * from their contributions on DScaler. |
| 11 | */ |
| 12 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 13 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Michael Krufky | ffbb807 | 2007-08-21 01:14:12 -0300 | [diff] [blame] | 15 | #include <linux/videodev.h> |
Michael Krufky | 8218b0b | 2007-06-26 13:12:08 -0300 | [diff] [blame] | 16 | #include "tuner-driver.h" |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 17 | |
| 18 | #define PREFIX "TEA5767 " |
| 19 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 20 | /* from tuner-core.c */ |
Hans Verkuil | f9195de | 2006-01-11 19:01:01 -0200 | [diff] [blame] | 21 | extern int tuner_debug; |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 22 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 23 | /*****************************************************************************/ |
| 24 | |
| 25 | /****************************** |
| 26 | * Write mode register values * |
| 27 | ******************************/ |
| 28 | |
| 29 | /* First register */ |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 30 | #define TEA5767_MUTE 0x80 /* Mutes output */ |
| 31 | #define TEA5767_SEARCH 0x40 /* Activates station search */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 32 | /* Bits 0-5 for divider MSB */ |
| 33 | |
| 34 | /* Second register */ |
| 35 | /* Bits 0-7 for divider LSB */ |
| 36 | |
| 37 | /* Third register */ |
| 38 | |
| 39 | /* Station search from botton to up */ |
| 40 | #define TEA5767_SEARCH_UP 0x80 |
| 41 | |
| 42 | /* Searches with ADC output = 10 */ |
| 43 | #define TEA5767_SRCH_HIGH_LVL 0x60 |
| 44 | |
| 45 | /* Searches with ADC output = 10 */ |
| 46 | #define TEA5767_SRCH_MID_LVL 0x40 |
| 47 | |
| 48 | /* Searches with ADC output = 5 */ |
| 49 | #define TEA5767_SRCH_LOW_LVL 0x20 |
| 50 | |
| 51 | /* if on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq) */ |
| 52 | #define TEA5767_HIGH_LO_INJECT 0x10 |
| 53 | |
| 54 | /* Disable stereo */ |
| 55 | #define TEA5767_MONO 0x08 |
| 56 | |
| 57 | /* Disable right channel and turns to mono */ |
| 58 | #define TEA5767_MUTE_RIGHT 0x04 |
| 59 | |
| 60 | /* Disable left channel and turns to mono */ |
| 61 | #define TEA5767_MUTE_LEFT 0x02 |
| 62 | |
| 63 | #define TEA5767_PORT1_HIGH 0x01 |
| 64 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 65 | /* Fourth register */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 66 | #define TEA5767_PORT2_HIGH 0x80 |
| 67 | /* Chips stops working. Only I2C bus remains on */ |
| 68 | #define TEA5767_STDBY 0x40 |
| 69 | |
| 70 | /* Japan freq (76-108 MHz. If disabled, 87.5-108 MHz */ |
| 71 | #define TEA5767_JAPAN_BAND 0x20 |
| 72 | |
| 73 | /* Unselected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz */ |
| 74 | #define TEA5767_XTAL_32768 0x10 |
| 75 | |
| 76 | /* Cuts weak signals */ |
| 77 | #define TEA5767_SOFT_MUTE 0x08 |
| 78 | |
| 79 | /* Activates high cut control */ |
| 80 | #define TEA5767_HIGH_CUT_CTRL 0x04 |
| 81 | |
| 82 | /* Activates stereo noise control */ |
| 83 | #define TEA5767_ST_NOISE_CTL 0x02 |
| 84 | |
| 85 | /* If activate PORT 1 indicates SEARCH or else it is used as PORT1 */ |
| 86 | #define TEA5767_SRCH_IND 0x01 |
| 87 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 88 | /* Fifth register */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 89 | |
| 90 | /* By activating, it will use Xtal at 13 MHz as reference for divider */ |
| 91 | #define TEA5767_PLLREF_ENABLE 0x80 |
| 92 | |
| 93 | /* By activating, deemphasis=50, or else, deemphasis of 50us */ |
| 94 | #define TEA5767_DEEMPH_75 0X40 |
| 95 | |
| 96 | /***************************** |
| 97 | * Read mode register values * |
| 98 | *****************************/ |
| 99 | |
| 100 | /* First register */ |
| 101 | #define TEA5767_READY_FLAG_MASK 0x80 |
| 102 | #define TEA5767_BAND_LIMIT_MASK 0X40 |
| 103 | /* Bits 0-5 for divider MSB after search or preset */ |
| 104 | |
| 105 | /* Second register */ |
| 106 | /* Bits 0-7 for divider LSB after search or preset */ |
| 107 | |
| 108 | /* Third register */ |
| 109 | #define TEA5767_STEREO_MASK 0x80 |
| 110 | #define TEA5767_IF_CNTR_MASK 0x7f |
| 111 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 112 | /* Fourth register */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 113 | #define TEA5767_ADC_LEVEL_MASK 0xf0 |
| 114 | |
| 115 | /* should be 0 */ |
| 116 | #define TEA5767_CHIP_ID_MASK 0x0f |
| 117 | |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 118 | /* Fifth register */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 119 | /* Reserved for future extensions */ |
| 120 | #define TEA5767_RESERVED_MASK 0xff |
| 121 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 122 | enum tea5767_xtal_freq { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 123 | TEA5767_LOW_LO_32768 = 0, |
| 124 | TEA5767_HIGH_LO_32768 = 1, |
| 125 | TEA5767_LOW_LO_13MHz = 2, |
| 126 | TEA5767_HIGH_LO_13MHz = 3, |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 130 | /*****************************************************************************/ |
| 131 | |
| 132 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 133 | { |
| 134 | struct tuner *t = i2c_get_clientdata(c); |
| 135 | |
| 136 | tuner_warn("This tuner doesn't support TV freq.\n"); |
| 137 | } |
| 138 | |
| 139 | static void tea5767_status_dump(unsigned char *buffer) |
| 140 | { |
| 141 | unsigned int div, frq; |
| 142 | |
| 143 | if (TEA5767_READY_FLAG_MASK & buffer[0]) |
| 144 | printk(PREFIX "Ready Flag ON\n"); |
| 145 | else |
| 146 | printk(PREFIX "Ready Flag OFF\n"); |
| 147 | |
| 148 | if (TEA5767_BAND_LIMIT_MASK & buffer[0]) |
| 149 | printk(PREFIX "Tuner at band limit\n"); |
| 150 | else |
| 151 | printk(PREFIX "Tuner not at band limit\n"); |
| 152 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 153 | div = ((buffer[0] & 0x3f) << 8) | buffer[1]; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 154 | |
| 155 | switch (TEA5767_HIGH_LO_32768) { |
| 156 | case TEA5767_HIGH_LO_13MHz: |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 157 | frq = (div * 50000 - 700000 - 225000) / 4; /* Freq in KHz */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 158 | break; |
| 159 | case TEA5767_LOW_LO_13MHz: |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 160 | frq = (div * 50000 + 700000 + 225000) / 4; /* Freq in KHz */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 161 | break; |
| 162 | case TEA5767_LOW_LO_32768: |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 163 | frq = (div * 32768 + 700000 + 225000) / 4; /* Freq in KHz */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 164 | break; |
| 165 | case TEA5767_HIGH_LO_32768: |
| 166 | default: |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 167 | frq = (div * 32768 - 700000 - 225000) / 4; /* Freq in KHz */ |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 168 | break; |
| 169 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 170 | buffer[0] = (div >> 8) & 0x3f; |
| 171 | buffer[1] = div & 0xff; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 172 | |
| 173 | printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n", |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 174 | frq / 1000, frq % 1000, div); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 175 | |
| 176 | if (TEA5767_STEREO_MASK & buffer[2]) |
| 177 | printk(PREFIX "Stereo\n"); |
| 178 | else |
| 179 | printk(PREFIX "Mono\n"); |
| 180 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 181 | printk(PREFIX "IF Counter = %d\n", buffer[2] & TEA5767_IF_CNTR_MASK); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 182 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 183 | printk(PREFIX "ADC Level = %d\n", |
| 184 | (buffer[3] & TEA5767_ADC_LEVEL_MASK) >> 4); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 185 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 186 | printk(PREFIX "Chip ID = %d\n", (buffer[3] & TEA5767_CHIP_ID_MASK)); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 187 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 188 | printk(PREFIX "Reserved = 0x%02x\n", |
| 189 | (buffer[4] & TEA5767_RESERVED_MASK)); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* Freq should be specifyed at 62.5 Hz */ |
| 193 | static void set_radio_freq(struct i2c_client *c, unsigned int frq) |
| 194 | { |
| 195 | struct tuner *t = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 196 | unsigned char buffer[5]; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 197 | unsigned div; |
| 198 | int rc; |
| 199 | |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 200 | tuner_dbg (PREFIX "radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 201 | |
| 202 | /* Rounds freq to next decimal value - for 62.5 KHz step */ |
| 203 | /* frq = 20*(frq/16)+radio_frq[frq%16]; */ |
| 204 | |
| 205 | buffer[2] = TEA5767_PORT1_HIGH; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 206 | buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | |
| 207 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; |
| 208 | buffer[4] = 0; |
| 209 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 210 | if (t->audmode == V4L2_TUNER_MODE_MONO) { |
| 211 | tuner_dbg("TEA5767 set to mono\n"); |
| 212 | buffer[2] |= TEA5767_MONO; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 213 | } else { |
| 214 | tuner_dbg("TEA5767 set to stereo\n"); |
| 215 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 216 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 217 | /* Should be replaced */ |
| 218 | switch (TEA5767_HIGH_LO_32768) { |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 219 | case TEA5767_HIGH_LO_13MHz: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 220 | tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 221 | buffer[2] |= TEA5767_HIGH_LO_INJECT; |
| 222 | buffer[4] |= TEA5767_PLLREF_ENABLE; |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 223 | div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 224 | break; |
| 225 | case TEA5767_LOW_LO_13MHz: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 226 | tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 13 MHz\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 227 | |
| 228 | buffer[4] |= TEA5767_PLLREF_ENABLE; |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 229 | div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 230 | break; |
| 231 | case TEA5767_LOW_LO_32768: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 232 | tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 233 | buffer[3] |= TEA5767_XTAL_32768; |
| 234 | /* const 700=4000*175 Khz - to adjust freq to right value */ |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 235 | div = ((frq * (4000 / 16) - 700000 - 225000) + 16384) >> 15; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 236 | break; |
| 237 | case TEA5767_HIGH_LO_32768: |
| 238 | default: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 239 | tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 240 | |
| 241 | buffer[2] |= TEA5767_HIGH_LO_INJECT; |
| 242 | buffer[3] |= TEA5767_XTAL_32768; |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 243 | div = ((frq * (4000 / 16) + 700000 + 225000) + 16384) >> 15; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 244 | break; |
| 245 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 246 | buffer[0] = (div >> 8) & 0x3f; |
| 247 | buffer[1] = div & 0xff; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 248 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 249 | if (5 != (rc = i2c_master_send(c, buffer, 5))) |
| 250 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 251 | |
Hans Verkuil | f9195de | 2006-01-11 19:01:01 -0200 | [diff] [blame] | 252 | if (tuner_debug) { |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 253 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) |
| 254 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
| 255 | else |
| 256 | tea5767_status_dump(buffer); |
| 257 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static int tea5767_signal(struct i2c_client *c) |
| 261 | { |
| 262 | unsigned char buffer[5]; |
| 263 | int rc; |
| 264 | struct tuner *t = i2c_get_clientdata(c); |
| 265 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 266 | memset(buffer, 0, sizeof(buffer)); |
| 267 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) |
| 268 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 269 | |
Hans Verkuil | f9a91f0 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 270 | return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static int tea5767_stereo(struct i2c_client *c) |
| 274 | { |
| 275 | unsigned char buffer[5]; |
| 276 | int rc; |
| 277 | struct tuner *t = i2c_get_clientdata(c); |
| 278 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 279 | memset(buffer, 0, sizeof(buffer)); |
| 280 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) |
| 281 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 282 | |
| 283 | rc = buffer[2] & TEA5767_STEREO_MASK; |
| 284 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 285 | tuner_dbg("TEA5767 radio ST GET = %02x\n", rc); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 286 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 287 | return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 290 | static void tea5767_standby(struct i2c_client *c) |
| 291 | { |
| 292 | unsigned char buffer[5]; |
| 293 | struct tuner *t = i2c_get_clientdata(c); |
| 294 | unsigned div, rc; |
| 295 | |
| 296 | div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ |
| 297 | buffer[0] = (div >> 8) & 0x3f; |
| 298 | buffer[1] = div & 0xff; |
| 299 | buffer[2] = TEA5767_PORT1_HIGH; |
| 300 | buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | |
| 301 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; |
| 302 | buffer[4] = 0; |
| 303 | |
| 304 | if (5 != (rc = i2c_master_send(c, buffer, 5))) |
| 305 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
| 306 | } |
| 307 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 308 | int tea5767_autodetection(struct i2c_client *c) |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 309 | { |
Mauro Carvalho Chehab | fd3113e | 2005-07-31 22:34:43 -0700 | [diff] [blame] | 310 | unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 311 | int rc; |
| 312 | struct tuner *t = i2c_get_clientdata(c); |
| 313 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 314 | if ((rc = i2c_master_recv(c, buffer, 7))< 5) { |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 315 | tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 316 | return EINVAL; |
| 317 | } |
| 318 | |
Mauro Carvalho Chehab | fd3113e | 2005-07-31 22:34:43 -0700 | [diff] [blame] | 319 | /* If all bytes are the same then it's a TV tuner and not a tea5767 */ |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 320 | if (buffer[0] == buffer[1] && buffer[0] == buffer[2] && |
| 321 | buffer[0] == buffer[3] && buffer[0] == buffer[4]) { |
| 322 | tuner_warn("All bytes are equal. It is not a TEA5767\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 323 | return EINVAL; |
| 324 | } |
| 325 | |
| 326 | /* Status bytes: |
| 327 | * Byte 4: bit 3:1 : CI (Chip Identification) == 0 |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 328 | * bit 0 : internally set to 0 |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 329 | * Byte 5: bit 7:0 : == 0 |
| 330 | */ |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 331 | if (((buffer[3] & 0x0f) != 0x00) || (buffer[4] != 0x00)) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 332 | tuner_warn("Chip ID is not zero. It is not a TEA5767\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 333 | return EINVAL; |
| 334 | } |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame] | 335 | |
Mauro Carvalho Chehab | 001abc9 | 2005-08-01 21:11:38 -0700 | [diff] [blame] | 336 | /* It seems that tea5767 returns 0xff after the 5th byte */ |
| 337 | if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) { |
| 338 | tuner_warn("Returned more than 5 bytes. It is not a TEA5767\n"); |
| 339 | return EINVAL; |
| 340 | } |
| 341 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 342 | tuner_warn("TEA5767 detected.\n"); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Michael Krufky | 0f838f8 | 2007-06-06 16:17:17 -0300 | [diff] [blame] | 346 | static struct tuner_operations tea5767_tuner_ops = { |
| 347 | .set_tv_freq = set_tv_freq, |
| 348 | .set_radio_freq = set_radio_freq, |
| 349 | .has_signal = tea5767_signal, |
| 350 | .is_stereo = tea5767_stereo, |
| 351 | .standby = tea5767_standby, |
| 352 | }; |
| 353 | |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 354 | int tea5767_tuner_init(struct i2c_client *c) |
| 355 | { |
| 356 | struct tuner *t = i2c_get_clientdata(c); |
| 357 | |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 358 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 359 | strlcpy(c->name, "tea5767", sizeof(c->name)); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 360 | |
Michael Krufky | 0f838f8 | 2007-06-06 16:17:17 -0300 | [diff] [blame] | 361 | memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 362 | |
| 363 | return (0); |
| 364 | } |