Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1 | /* |
| 2 | * Programming the mspx4xx sound processor family |
| 3 | * |
| 4 | * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/i2c.h> |
| 26 | #include <linux/videodev.h> |
| 27 | #include <linux/videodev2.h> |
| 28 | #include <media/v4l2-common.h> |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 29 | #include <linux/kthread.h> |
| 30 | #include <linux/suspend.h> |
| 31 | #include "msp3400.h" |
| 32 | |
| 33 | /* this one uses the automatic sound standard detection of newer msp34xx |
| 34 | chip versions */ |
| 35 | static struct { |
| 36 | int retval; |
| 37 | int main, second; |
| 38 | char *name; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 39 | } msp_stdlist[] = { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 40 | { 0x0000, 0, 0, "could not detect sound standard" }, |
| 41 | { 0x0001, 0, 0, "autodetect start" }, |
| 42 | { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" }, |
| 43 | { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" }, |
| 44 | { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" }, |
| 45 | { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" }, |
| 46 | { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" }, |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 47 | { 0x0007, MSP_CARRIER(6.5), MSP_CARRIER(5.7421875), "6.5/5.74 D/K3 Dual FM-Stereo" }, |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 48 | { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" }, |
| 49 | { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" }, |
| 50 | { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" }, |
| 51 | { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" }, |
| 52 | { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" }, |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 53 | { 0x000d, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV3)" }, |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 54 | { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" }, |
| 55 | { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" }, |
| 56 | { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" }, |
| 57 | { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" }, |
| 58 | { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" }, |
| 59 | { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" }, |
| 60 | { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" }, |
| 61 | { -1, 0, 0, NULL }, /* EOF */ |
| 62 | }; |
| 63 | |
| 64 | static struct msp3400c_init_data_dem { |
| 65 | int fir1[6]; |
| 66 | int fir2[6]; |
| 67 | int cdo1; |
| 68 | int cdo2; |
| 69 | int ad_cv; |
| 70 | int mode_reg; |
| 71 | int dsp_src; |
| 72 | int dsp_matrix; |
| 73 | } msp3400c_init_data[] = { |
| 74 | { /* AM (for carrier detect / msp3400) */ |
| 75 | {75, 19, 36, 35, 39, 40}, |
| 76 | {75, 19, 36, 35, 39, 40}, |
| 77 | MSP_CARRIER(5.5), MSP_CARRIER(5.5), |
| 78 | 0x00d0, 0x0500, 0x0020, 0x3000 |
| 79 | },{ /* AM (for carrier detect / msp3410) */ |
| 80 | {-1, -1, -8, 2, 59, 126}, |
| 81 | {-1, -1, -8, 2, 59, 126}, |
| 82 | MSP_CARRIER(5.5), MSP_CARRIER(5.5), |
| 83 | 0x00d0, 0x0100, 0x0020, 0x3000 |
| 84 | },{ /* FM Radio */ |
| 85 | {-8, -8, 4, 6, 78, 107}, |
| 86 | {-8, -8, 4, 6, 78, 107}, |
| 87 | MSP_CARRIER(10.7), MSP_CARRIER(10.7), |
| 88 | 0x00d0, 0x0480, 0x0020, 0x3000 |
| 89 | },{ /* Terrestial FM-mono + FM-stereo */ |
| 90 | {3, 18, 27, 48, 66, 72}, |
| 91 | {3, 18, 27, 48, 66, 72}, |
| 92 | MSP_CARRIER(5.5), MSP_CARRIER(5.5), |
| 93 | 0x00d0, 0x0480, 0x0030, 0x3000 |
| 94 | },{ /* Sat FM-mono */ |
| 95 | { 1, 9, 14, 24, 33, 37}, |
| 96 | { 3, 18, 27, 48, 66, 72}, |
| 97 | MSP_CARRIER(6.5), MSP_CARRIER(6.5), |
| 98 | 0x00c6, 0x0480, 0x0000, 0x3000 |
| 99 | },{ /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */ |
| 100 | {-2, -8, -10, 10, 50, 86}, |
| 101 | {3, 18, 27, 48, 66, 72}, |
| 102 | MSP_CARRIER(5.5), MSP_CARRIER(5.5), |
| 103 | 0x00d0, 0x0040, 0x0120, 0x3000 |
| 104 | },{ /* NICAM/FM -- I (6.0/6.552) */ |
| 105 | {2, 4, -6, -4, 40, 94}, |
| 106 | {3, 18, 27, 48, 66, 72}, |
| 107 | MSP_CARRIER(6.0), MSP_CARRIER(6.0), |
| 108 | 0x00d0, 0x0040, 0x0120, 0x3000 |
| 109 | },{ /* NICAM/AM -- L (6.5/5.85) */ |
| 110 | {-2, -8, -10, 10, 50, 86}, |
| 111 | {-4, -12, -9, 23, 79, 126}, |
| 112 | MSP_CARRIER(6.5), MSP_CARRIER(6.5), |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 113 | 0x00c6, 0x0140, 0x0120, 0x7c00 |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 114 | }, |
| 115 | }; |
| 116 | |
| 117 | struct msp3400c_carrier_detect { |
| 118 | int cdo; |
| 119 | char *name; |
| 120 | }; |
| 121 | |
| 122 | static struct msp3400c_carrier_detect msp3400c_carrier_detect_main[] = { |
| 123 | /* main carrier */ |
| 124 | { MSP_CARRIER(4.5), "4.5 NTSC" }, |
| 125 | { MSP_CARRIER(5.5), "5.5 PAL B/G" }, |
| 126 | { MSP_CARRIER(6.0), "6.0 PAL I" }, |
| 127 | { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" } |
| 128 | }; |
| 129 | |
| 130 | static struct msp3400c_carrier_detect msp3400c_carrier_detect_55[] = { |
| 131 | /* PAL B/G */ |
| 132 | { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" }, |
| 133 | { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" } |
| 134 | }; |
| 135 | |
| 136 | static struct msp3400c_carrier_detect msp3400c_carrier_detect_65[] = { |
| 137 | /* PAL SAT / SECAM */ |
| 138 | { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" }, |
| 139 | { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" }, |
| 140 | { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" }, |
| 141 | { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" }, |
| 142 | { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" }, |
| 143 | { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" }, |
| 144 | }; |
| 145 | |
| 146 | /* ------------------------------------------------------------------------ */ |
| 147 | |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 148 | const char *msp_standard_std_name(int std) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 149 | { |
| 150 | int i; |
| 151 | |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 152 | for (i = 0; msp_stdlist[i].name != NULL; i++) |
| 153 | if (msp_stdlist[i].retval == std) |
| 154 | return msp_stdlist[i].name; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 155 | return "unknown"; |
| 156 | } |
| 157 | |
Adrian Bunk | 044f324 | 2006-03-08 10:50:07 -0300 | [diff] [blame] | 158 | static void msp_set_source(struct i2c_client *client, u16 src) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 159 | { |
| 160 | struct msp_state *state = i2c_get_clientdata(client); |
| 161 | |
| 162 | if (msp_dolby) { |
| 163 | msp_write_dsp(client, 0x0008, 0x0520); /* I2S1 */ |
| 164 | msp_write_dsp(client, 0x0009, 0x0620); /* I2S2 */ |
| 165 | } else { |
| 166 | msp_write_dsp(client, 0x0008, src); |
| 167 | msp_write_dsp(client, 0x0009, src); |
| 168 | } |
| 169 | msp_write_dsp(client, 0x000a, src); |
| 170 | msp_write_dsp(client, 0x000b, src); |
| 171 | msp_write_dsp(client, 0x000c, src); |
| 172 | if (state->has_scart23_in_scart2_out) |
| 173 | msp_write_dsp(client, 0x0041, src); |
| 174 | } |
| 175 | |
| 176 | void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 177 | { |
| 178 | msp_write_dem(client, 0x0093, cdo1 & 0xfff); |
| 179 | msp_write_dem(client, 0x009b, cdo1 >> 12); |
| 180 | msp_write_dem(client, 0x00a3, cdo2 & 0xfff); |
| 181 | msp_write_dem(client, 0x00ab, cdo2 >> 12); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 182 | msp_write_dem(client, 0x0056, 0); /* LOAD_REG_1/2 */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 183 | } |
| 184 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 185 | void msp3400c_set_mode(struct i2c_client *client, int mode) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 186 | { |
| 187 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 188 | struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode]; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 189 | int i; |
| 190 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 191 | v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode); |
| 192 | state->mode = mode; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 193 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 194 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 195 | msp_write_dem(client, 0x00bb, data->ad_cv); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 196 | |
| 197 | for (i = 5; i >= 0; i--) /* fir 1 */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 198 | msp_write_dem(client, 0x0001, data->fir1[i]); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 199 | |
| 200 | msp_write_dem(client, 0x0005, 0x0004); /* fir 2 */ |
| 201 | msp_write_dem(client, 0x0005, 0x0040); |
| 202 | msp_write_dem(client, 0x0005, 0x0000); |
| 203 | for (i = 5; i >= 0; i--) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 204 | msp_write_dem(client, 0x0005, data->fir2[i]); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 205 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 206 | msp_write_dem(client, 0x0083, data->mode_reg); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 207 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 208 | msp3400c_set_carrier(client, data->cdo1, data->cdo2); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 209 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 210 | msp_set_source(client, data->dsp_src); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 211 | /* set prescales */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 212 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 213 | /* volume prescale for SCART (AM mono input) */ |
| 214 | msp_write_dsp(client, 0x000d, 0x1900); |
| 215 | msp_write_dsp(client, 0x000e, data->dsp_matrix); |
| 216 | if (state->has_nicam) /* nicam prescale */ |
| 217 | msp_write_dsp(client, 0x0010, 0x5a00); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 218 | } |
| 219 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 220 | /* Set audio mode. Note that the pre-'G' models do not support BTSC+SAP, |
| 221 | nor do they support stereo BTSC. */ |
Adrian Bunk | 044f324 | 2006-03-08 10:50:07 -0300 | [diff] [blame] | 222 | static void msp3400c_set_audmode(struct i2c_client *client) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 223 | { |
Hans Verkuil | d312a46 | 2006-01-09 18:21:36 -0200 | [diff] [blame] | 224 | static char *strmode[] = { "mono", "stereo", "lang2", "lang1" }; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 225 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 226 | char *modestr = (state->audmode >= 0 && state->audmode < 4) ? |
| 227 | strmode[state->audmode] : "unknown"; |
| 228 | int src = 0; /* channel source: FM/AM, nicam or SCART */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 229 | |
| 230 | if (state->opmode == OPMODE_AUTOSELECT) { |
| 231 | /* this method would break everything, let's make sure |
| 232 | * it's never called |
| 233 | */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 234 | v4l_dbg(1, msp_debug, client, |
| 235 | "set_audmode called with mode=%d instead of set_source (ignored)\n", |
| 236 | state->audmode); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 237 | return; |
| 238 | } |
| 239 | |
| 240 | /* switch demodulator */ |
| 241 | switch (state->mode) { |
| 242 | case MSP_MODE_FM_TERRA: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 243 | v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr); |
| 244 | switch (state->audmode) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 245 | case V4L2_TUNER_MODE_STEREO: |
| 246 | msp_write_dsp(client, 0x000e, 0x3001); |
| 247 | break; |
| 248 | case V4L2_TUNER_MODE_MONO: |
| 249 | case V4L2_TUNER_MODE_LANG1: |
| 250 | case V4L2_TUNER_MODE_LANG2: |
| 251 | msp_write_dsp(client, 0x000e, 0x3000); |
| 252 | break; |
| 253 | } |
| 254 | break; |
| 255 | case MSP_MODE_FM_SAT: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 256 | v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr); |
| 257 | switch (state->audmode) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 258 | case V4L2_TUNER_MODE_MONO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 259 | msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 260 | break; |
| 261 | case V4L2_TUNER_MODE_STEREO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 262 | msp3400c_set_carrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02)); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 263 | break; |
| 264 | case V4L2_TUNER_MODE_LANG1: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 265 | msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02)); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 266 | break; |
| 267 | case V4L2_TUNER_MODE_LANG2: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 268 | msp3400c_set_carrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02)); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 269 | break; |
| 270 | } |
| 271 | break; |
| 272 | case MSP_MODE_FM_NICAM1: |
| 273 | case MSP_MODE_FM_NICAM2: |
| 274 | case MSP_MODE_AM_NICAM: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 275 | v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 276 | if (state->nicam_on) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 277 | src = 0x0100; /* NICAM */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 278 | break; |
| 279 | case MSP_MODE_BTSC: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 280 | v4l_dbg(1, msp_debug, client, "BTSC set_audmode: %s\n",modestr); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 281 | break; |
| 282 | case MSP_MODE_EXTERN: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 283 | v4l_dbg(1, msp_debug, client, "extern set_audmode: %s\n",modestr); |
| 284 | src = 0x0200; /* SCART */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 285 | break; |
| 286 | case MSP_MODE_FM_RADIO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 287 | v4l_dbg(1, msp_debug, client, "FM-Radio set_audmode: %s\n",modestr); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 288 | break; |
| 289 | default: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 290 | v4l_dbg(1, msp_debug, client, "mono set_audmode\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
| 294 | /* switch audio */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 295 | switch (state->audmode) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 296 | case V4L2_TUNER_MODE_STEREO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 297 | src |= 0x0020; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 298 | break; |
| 299 | case V4L2_TUNER_MODE_MONO: |
| 300 | if (state->mode == MSP_MODE_AM_NICAM) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 301 | v4l_dbg(1, msp_debug, client, "switching to AM mono\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 302 | /* AM mono decoding is handled by tuner, not MSP chip */ |
| 303 | /* SCART switching control register */ |
| 304 | msp_set_scart(client, SCART_MONO, 0); |
| 305 | src = 0x0200; |
| 306 | break; |
| 307 | } |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 308 | if (state->rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 309 | src = 0x0030; |
| 310 | break; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 311 | case V4L2_TUNER_MODE_LANG1: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 312 | /* switch to stereo for stereo transmission, otherwise |
| 313 | keep first language */ |
| 314 | if (state->rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 315 | src |= 0x0020; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 316 | break; |
| 317 | case V4L2_TUNER_MODE_LANG2: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 318 | src |= 0x0010; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 319 | break; |
| 320 | } |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 321 | v4l_dbg(1, msp_debug, client, "set_audmode final source/matrix = 0x%x\n", src); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 322 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 323 | msp_set_source(client, src); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void msp3400c_print_mode(struct i2c_client *client) |
| 327 | { |
| 328 | struct msp_state *state = i2c_get_clientdata(client); |
| 329 | |
| 330 | if (state->main == state->second) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 331 | v4l_dbg(1, msp_debug, client, "mono sound carrier: %d.%03d MHz\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 332 | state->main / 910000, (state->main / 910) % 1000); |
| 333 | } else { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 334 | v4l_dbg(1, msp_debug, client, "main sound carrier: %d.%03d MHz\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 335 | state->main / 910000, (state->main / 910) % 1000); |
| 336 | } |
| 337 | if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2) |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 338 | v4l_dbg(1, msp_debug, client, "NICAM/FM carrier : %d.%03d MHz\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 339 | state->second / 910000, (state->second/910) % 1000); |
| 340 | if (state->mode == MSP_MODE_AM_NICAM) |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 341 | v4l_dbg(1, msp_debug, client, "NICAM/AM carrier : %d.%03d MHz\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 342 | state->second / 910000, (state->second / 910) % 1000); |
| 343 | if (state->mode == MSP_MODE_FM_TERRA && state->main != state->second) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 344 | v4l_dbg(1, msp_debug, client, "FM-stereo carrier : %d.%03d MHz\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 345 | state->second / 910000, (state->second / 910) % 1000); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* ----------------------------------------------------------------------- */ |
| 350 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 351 | static int msp3400c_detect_stereo(struct i2c_client *client) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 352 | { |
| 353 | struct msp_state *state = i2c_get_clientdata(client); |
| 354 | int val; |
| 355 | int rxsubchans = state->rxsubchans; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 356 | int newnicam = state->nicam_on; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 357 | int update = 0; |
| 358 | |
| 359 | switch (state->mode) { |
| 360 | case MSP_MODE_FM_TERRA: |
| 361 | val = msp_read_dsp(client, 0x18); |
| 362 | if (val > 32767) |
| 363 | val -= 65536; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 364 | v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 365 | if (val > 4096) { |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 366 | rxsubchans = V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 367 | } else if (val < -4096) { |
| 368 | rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; |
| 369 | } else { |
| 370 | rxsubchans = V4L2_TUNER_SUB_MONO; |
| 371 | } |
| 372 | newnicam = 0; |
| 373 | break; |
| 374 | case MSP_MODE_FM_NICAM1: |
| 375 | case MSP_MODE_FM_NICAM2: |
| 376 | case MSP_MODE_AM_NICAM: |
| 377 | val = msp_read_dem(client, 0x23); |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 378 | v4l_dbg(2, msp_debug, client, "nicam sync=%d, mode=%d\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 379 | val & 1, (val & 0x1e) >> 1); |
| 380 | |
| 381 | if (val & 1) { |
| 382 | /* nicam synced */ |
| 383 | switch ((val & 0x1e) >> 1) { |
| 384 | case 0: |
| 385 | case 8: |
| 386 | rxsubchans = V4L2_TUNER_SUB_STEREO; |
| 387 | break; |
| 388 | case 1: |
| 389 | case 9: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 390 | rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 391 | break; |
| 392 | case 2: |
| 393 | case 10: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 394 | rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 395 | break; |
| 396 | default: |
| 397 | rxsubchans = V4L2_TUNER_SUB_MONO; |
| 398 | break; |
| 399 | } |
| 400 | newnicam = 1; |
| 401 | } else { |
| 402 | newnicam = 0; |
| 403 | rxsubchans = V4L2_TUNER_SUB_MONO; |
| 404 | } |
| 405 | break; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 406 | } |
| 407 | if (rxsubchans != state->rxsubchans) { |
| 408 | update = 1; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 409 | v4l_dbg(1, msp_debug, client, "watch: rxsubchans %02x => %02x\n", |
| 410 | state->rxsubchans, rxsubchans); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 411 | state->rxsubchans = rxsubchans; |
| 412 | } |
| 413 | if (newnicam != state->nicam_on) { |
| 414 | update = 1; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 415 | v4l_dbg(1, msp_debug, client, "watch: nicam %d => %d\n", |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 416 | state->nicam_on, newnicam); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 417 | state->nicam_on = newnicam; |
| 418 | } |
| 419 | return update; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * A kernel thread for msp3400 control -- we don't want to block the |
| 424 | * in the ioctl while doing the sound carrier & stereo detect |
| 425 | */ |
| 426 | /* stereo/multilang monitoring */ |
| 427 | static void watch_stereo(struct i2c_client *client) |
| 428 | { |
| 429 | struct msp_state *state = i2c_get_clientdata(client); |
| 430 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 431 | if (msp_detect_stereo(client)) { |
| 432 | msp_set_audmode(client); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 433 | } |
| 434 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 435 | if (msp_once) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 436 | state->watch_stereo = 0; |
| 437 | } |
| 438 | |
| 439 | int msp3400c_thread(void *data) |
| 440 | { |
| 441 | struct i2c_client *client = data; |
| 442 | struct msp_state *state = i2c_get_clientdata(client); |
| 443 | struct msp3400c_carrier_detect *cd; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 444 | int count, max1, max2, val1, val2, val, this; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 445 | |
| 446 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 447 | v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 448 | for (;;) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 449 | v4l_dbg(2, msp_debug, client, "msp3400 thread: sleep\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 450 | msp_sleep(state, -1); |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 451 | v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 452 | |
| 453 | restart: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 454 | v4l_dbg(2, msp_debug, client, "thread: restart scan\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 455 | state->restart = 0; |
| 456 | if (kthread_should_stop()) |
| 457 | break; |
| 458 | |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 459 | if (state->radio || MSP_MODE_EXTERN == state->mode) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 460 | /* no carrier scan, just unmute */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 461 | v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 462 | msp_set_audio(client); |
| 463 | continue; |
| 464 | } |
| 465 | |
| 466 | /* mute */ |
| 467 | msp_set_mute(client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 468 | msp3400c_set_mode(client, MSP_MODE_AM_DETECT); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 469 | val1 = val2 = 0; |
| 470 | max1 = max2 = -1; |
| 471 | state->watch_stereo = 0; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 472 | state->nicam_on = 0; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 473 | |
| 474 | /* some time for the tuner to sync */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 475 | if (msp_sleep(state, 200)) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 476 | goto restart; |
| 477 | |
| 478 | /* carrier detect pass #1 -- main carrier */ |
| 479 | cd = msp3400c_carrier_detect_main; |
| 480 | count = ARRAY_SIZE(msp3400c_carrier_detect_main); |
| 481 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 482 | if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 483 | /* autodetect doesn't work well with AM ... */ |
| 484 | max1 = 3; |
| 485 | count = 0; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 486 | v4l_dbg(1, msp_debug, client, "AM sound override\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | for (this = 0; this < count; this++) { |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 490 | msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 491 | if (msp_sleep(state,100)) |
| 492 | goto restart; |
| 493 | val = msp_read_dsp(client, 0x1b); |
| 494 | if (val > 32767) |
| 495 | val -= 65536; |
| 496 | if (val1 < val) |
| 497 | val1 = val, max1 = this; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 498 | v4l_dbg(1, msp_debug, client, "carrier1 val: %5d / %s\n", val,cd[this].name); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* carrier detect pass #2 -- second (stereo) carrier */ |
| 502 | switch (max1) { |
| 503 | case 1: /* 5.5 */ |
| 504 | cd = msp3400c_carrier_detect_55; |
| 505 | count = ARRAY_SIZE(msp3400c_carrier_detect_55); |
| 506 | break; |
| 507 | case 3: /* 6.5 */ |
| 508 | cd = msp3400c_carrier_detect_65; |
| 509 | count = ARRAY_SIZE(msp3400c_carrier_detect_65); |
| 510 | break; |
| 511 | case 0: /* 4.5 */ |
| 512 | case 2: /* 6.0 */ |
| 513 | default: |
| 514 | cd = NULL; |
| 515 | count = 0; |
| 516 | break; |
| 517 | } |
| 518 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 519 | if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 520 | /* autodetect doesn't work well with AM ... */ |
| 521 | cd = NULL; |
| 522 | count = 0; |
| 523 | max2 = 0; |
| 524 | } |
| 525 | for (this = 0; this < count; this++) { |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 526 | msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 527 | if (msp_sleep(state,100)) |
| 528 | goto restart; |
| 529 | val = msp_read_dsp(client, 0x1b); |
| 530 | if (val > 32767) |
| 531 | val -= 65536; |
| 532 | if (val2 < val) |
| 533 | val2 = val, max2 = this; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 534 | v4l_dbg(1, msp_debug, client, "carrier2 val: %5d / %s\n", val,cd[this].name); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* program the msp3400 according to the results */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 538 | state->main = msp3400c_carrier_detect_main[max1].cdo; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 539 | switch (max1) { |
| 540 | case 1: /* 5.5 */ |
| 541 | if (max2 == 0) { |
| 542 | /* B/G FM-stereo */ |
| 543 | state->second = msp3400c_carrier_detect_55[max2].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 544 | msp3400c_set_mode(client, MSP_MODE_FM_TERRA); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 545 | state->watch_stereo = 1; |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 546 | } else if (max2 == 1 && state->has_nicam) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 547 | /* B/G NICAM */ |
| 548 | state->second = msp3400c_carrier_detect_55[max2].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 549 | msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); |
| 550 | msp3400c_set_carrier(client, state->second, state->main); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 551 | state->nicam_on = 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 552 | state->watch_stereo = 1; |
| 553 | } else { |
| 554 | goto no_second; |
| 555 | } |
| 556 | break; |
| 557 | case 2: /* 6.0 */ |
| 558 | /* PAL I NICAM */ |
| 559 | state->second = MSP_CARRIER(6.552); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 560 | msp3400c_set_mode(client, MSP_MODE_FM_NICAM2); |
| 561 | msp3400c_set_carrier(client, state->second, state->main); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 562 | state->nicam_on = 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 563 | state->watch_stereo = 1; |
| 564 | break; |
| 565 | case 3: /* 6.5 */ |
| 566 | if (max2 == 1 || max2 == 2) { |
| 567 | /* D/K FM-stereo */ |
| 568 | state->second = msp3400c_carrier_detect_65[max2].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 569 | msp3400c_set_mode(client, MSP_MODE_FM_TERRA); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 570 | state->watch_stereo = 1; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 571 | } else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 572 | /* L NICAM or AM-mono */ |
| 573 | state->second = msp3400c_carrier_detect_65[max2].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 574 | msp3400c_set_mode(client, MSP_MODE_AM_NICAM); |
| 575 | msp3400c_set_carrier(client, state->second, state->main); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 576 | state->watch_stereo = 1; |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 577 | } else if (max2 == 0 && state->has_nicam) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 578 | /* D/K NICAM */ |
| 579 | state->second = msp3400c_carrier_detect_65[max2].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 580 | msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); |
| 581 | msp3400c_set_carrier(client, state->second, state->main); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 582 | state->nicam_on = 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 583 | state->watch_stereo = 1; |
| 584 | } else { |
| 585 | goto no_second; |
| 586 | } |
| 587 | break; |
| 588 | case 0: /* 4.5 */ |
| 589 | default: |
| 590 | no_second: |
| 591 | state->second = msp3400c_carrier_detect_main[max1].cdo; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 592 | msp3400c_set_mode(client, MSP_MODE_FM_TERRA); |
| 593 | msp3400c_set_carrier(client, state->second, state->main); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 594 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 595 | break; |
| 596 | } |
| 597 | |
| 598 | /* unmute */ |
| 599 | msp_set_audio(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 600 | msp3400c_set_audmode(client); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 601 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 602 | if (msp_debug) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 603 | msp3400c_print_mode(client); |
| 604 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 605 | /* monitor tv audio mode, the first time don't wait |
| 606 | so long to get a quick stereo/bilingual result */ |
| 607 | if (msp_sleep(state, 1000)) |
| 608 | goto restart; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 609 | while (state->watch_stereo) { |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 610 | if (msp_sleep(state, 5000)) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 611 | goto restart; |
| 612 | watch_stereo(client); |
| 613 | } |
| 614 | } |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 615 | v4l_dbg(1, msp_debug, client, "thread: exit\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | |
| 620 | int msp3410d_thread(void *data) |
| 621 | { |
| 622 | struct i2c_client *client = data; |
| 623 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | d312a46 | 2006-01-09 18:21:36 -0200 | [diff] [blame] | 624 | int val, i, std; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 625 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 626 | v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 627 | |
| 628 | for (;;) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 629 | v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 630 | msp_sleep(state,-1); |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 631 | v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 632 | |
| 633 | restart: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 634 | v4l_dbg(2, msp_debug, client, "thread: restart scan\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 635 | state->restart = 0; |
| 636 | if (kthread_should_stop()) |
| 637 | break; |
| 638 | |
| 639 | if (state->mode == MSP_MODE_EXTERN) { |
| 640 | /* no carrier scan needed, just unmute */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 641 | v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 642 | msp_set_audio(client); |
| 643 | continue; |
| 644 | } |
| 645 | |
| 646 | /* put into sane state (and mute) */ |
| 647 | msp_reset(client); |
| 648 | |
| 649 | /* some time for the tuner to sync */ |
| 650 | if (msp_sleep(state,200)) |
| 651 | goto restart; |
| 652 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 653 | /* start autodetect. Note: autodetect is not supported for |
| 654 | NTSC-M and radio, hence we force the standard in those cases. */ |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 655 | if (state->radio) |
| 656 | std = 0x40; |
Hans Verkuil | d312a46 | 2006-01-09 18:21:36 -0200 | [diff] [blame] | 657 | else |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 658 | std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 659 | state->watch_stereo = 0; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 660 | state->nicam_on = 0; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 661 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 662 | if (msp_debug) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 663 | v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n", |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 664 | msp_standard_std_name(std), std); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 665 | |
| 666 | if (std != 1) { |
| 667 | /* programmed some specific mode */ |
| 668 | val = std; |
| 669 | } else { |
| 670 | /* triggered autodetect */ |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 671 | msp_write_dem(client, 0x20, std); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 672 | for (;;) { |
Hans Verkuil | d312a46 | 2006-01-09 18:21:36 -0200 | [diff] [blame] | 673 | if (msp_sleep(state, 100)) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 674 | goto restart; |
| 675 | |
| 676 | /* check results */ |
| 677 | val = msp_read_dem(client, 0x7e); |
| 678 | if (val < 0x07ff) |
| 679 | break; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 680 | v4l_dbg(2, msp_debug, client, "detection still in progress\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 681 | } |
| 682 | } |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 683 | for (i = 0; msp_stdlist[i].name != NULL; i++) |
| 684 | if (msp_stdlist[i].retval == val) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 685 | break; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 686 | v4l_dbg(1, msp_debug, client, "current standard: %s (0x%04x)\n", |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 687 | msp_standard_std_name(val), val); |
| 688 | state->main = msp_stdlist[i].main; |
| 689 | state->second = msp_stdlist[i].second; |
| 690 | state->std = val; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 691 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 692 | if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) && |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 693 | (val != 0x0009)) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 694 | /* autodetection has failed, let backup */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 695 | v4l_dbg(1, msp_debug, client, "autodetection failed," |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 696 | " switching to backup standard: %s (0x%04x)\n", |
| 697 | msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 698 | state->std = val = 0x0009; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 699 | msp_write_dem(client, 0x20, val); |
| 700 | } |
| 701 | |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 702 | /* set stereo */ |
| 703 | switch (val) { |
| 704 | case 0x0008: /* B/G NICAM */ |
| 705 | case 0x000a: /* I NICAM */ |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 706 | case 0x000b: /* D/K NICAM */ |
| 707 | if (val == 0x000a) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 708 | state->mode = MSP_MODE_FM_NICAM2; |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 709 | else |
| 710 | state->mode = MSP_MODE_FM_NICAM1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 711 | /* just turn on stereo */ |
| 712 | state->rxsubchans = V4L2_TUNER_SUB_STEREO; |
| 713 | state->nicam_on = 1; |
| 714 | state->watch_stereo = 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 715 | break; |
| 716 | case 0x0009: |
| 717 | state->mode = MSP_MODE_AM_NICAM; |
| 718 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 719 | state->nicam_on = 1; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 720 | state->watch_stereo = 1; |
| 721 | break; |
| 722 | case 0x0020: /* BTSC */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 723 | /* The pre-'G' models only have BTSC-mono */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 724 | state->mode = MSP_MODE_BTSC; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 725 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 726 | break; |
| 727 | case 0x0040: /* FM radio */ |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 728 | state->mode = MSP_MODE_FM_RADIO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 729 | state->rxsubchans = V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 730 | /* not needed in theory if we have radio, but |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 731 | short programming enables carrier mute */ |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 732 | msp3400c_set_mode(client, MSP_MODE_FM_RADIO); |
| 733 | msp3400c_set_carrier(client, MSP_CARRIER(10.7), |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 734 | MSP_CARRIER(10.7)); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 735 | /* scart routing (this doesn't belong here I think) */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 736 | msp_set_scart(client,SCART_IN2,0); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 737 | break; |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 738 | case 0x0002: |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 739 | case 0x0003: |
| 740 | case 0x0004: |
| 741 | case 0x0005: |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 742 | state->mode = MSP_MODE_FM_TERRA; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 743 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 744 | state->watch_stereo = 1; |
| 745 | break; |
| 746 | } |
| 747 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 748 | /* set various prescales */ |
| 749 | msp_write_dsp(client, 0x0d, 0x1900); /* scart */ |
| 750 | msp_write_dsp(client, 0x0e, 0x3000); /* FM */ |
| 751 | if (state->has_nicam) |
| 752 | msp_write_dsp(client, 0x10, 0x5a00); /* nicam */ |
| 753 | |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 754 | if (state->has_i2s_conf) |
| 755 | msp_write_dem(client, 0x40, state->i2s_mode); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 756 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 757 | /* unmute, restore misc registers */ |
| 758 | msp_set_audio(client); |
| 759 | |
| 760 | msp_write_dsp(client, 0x13, state->acb); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 761 | msp3400c_set_audmode(client); |
| 762 | |
| 763 | /* monitor tv audio mode, the first time don't wait |
| 764 | so long to get a quick stereo/bilingual result */ |
| 765 | if (msp_sleep(state, 1000)) |
| 766 | goto restart; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 767 | while (state->watch_stereo) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 768 | watch_stereo(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 769 | if (msp_sleep(state, 5000)) |
| 770 | goto restart; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 771 | } |
| 772 | } |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 773 | v4l_dbg(1, msp_debug, client, "thread: exit\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | /* ----------------------------------------------------------------------- */ |
| 778 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 779 | /* msp34xxG + (autoselect no-thread) |
| 780 | * this one uses both automatic standard detection and automatic sound |
| 781 | * select which are available in the newer G versions |
| 782 | * struct msp: only norm, acb and source are really used in this mode |
| 783 | */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 784 | |
| 785 | /* set the same 'source' for the loudspeaker, scart and quasi-peak detector |
| 786 | * the value for source is the same as bit 15:8 of DSP registers 0x08, |
| 787 | * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 788 | */ |
| 789 | static void msp34xxg_set_source(struct i2c_client *client, int source) |
| 790 | { |
| 791 | struct msp_state *state = i2c_get_clientdata(client); |
| 792 | |
| 793 | /* fix matrix mode to stereo and let the msp choose what |
| 794 | * to output according to 'source', as recommended |
| 795 | * for MONO (source==0) downmixing set bit[7:0] to 0x30 |
| 796 | */ |
| 797 | int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20); |
| 798 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 799 | v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 800 | msp_set_source(client, value); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 801 | /* |
| 802 | * set identification threshold. Personally, I |
| 803 | * I set it to a higher value that the default |
| 804 | * of 0x190 to ignore noisy stereo signals. |
| 805 | * this needs tuning. (recommended range 0x00a0-0x03c0) |
| 806 | * 0x7f0 = forced mono mode |
| 807 | */ |
| 808 | /* a2 threshold for stereo/bilingual */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 809 | msp_write_dem(client, 0x22, msp_stereo_thresh); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 810 | state->source = source; |
| 811 | } |
| 812 | |
Hans Verkuil | 9a80a93 | 2006-03-19 07:25:42 -0300 | [diff] [blame] | 813 | static int msp34xxg_modus(struct i2c_client *client) |
| 814 | { |
| 815 | struct msp_state *state = i2c_get_clientdata(client); |
| 816 | |
| 817 | if (state->radio) { |
| 818 | v4l_dbg(1, msp_debug, client, "selected radio modus\n"); |
| 819 | return 0x0001; |
| 820 | } |
| 821 | |
| 822 | if (state->v4l2_std & V4L2_STD_PAL) { |
| 823 | v4l_dbg(1, msp_debug, client, "selected PAL modus\n"); |
| 824 | return 0x7001; |
| 825 | } |
| 826 | if (state->v4l2_std == V4L2_STD_NTSC_M_JP) { |
| 827 | v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n"); |
| 828 | return 0x4001; |
| 829 | } |
| 830 | if (state->v4l2_std == V4L2_STD_NTSC_M_KR) { |
| 831 | v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n"); |
| 832 | return 0x0001; |
| 833 | } |
| 834 | if (state->v4l2_std & V4L2_STD_MN) { |
| 835 | v4l_dbg(1, msp_debug, client, "selected M (BTSC) modus\n"); |
| 836 | return 0x2001; |
| 837 | } |
| 838 | if (state->v4l2_std & V4L2_STD_SECAM) { |
| 839 | v4l_dbg(1, msp_debug, client, "selected SECAM modus\n"); |
| 840 | return 0x6001; |
| 841 | } |
| 842 | return 0x0001; |
| 843 | } |
| 844 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 845 | /* (re-)initialize the msp34xxg */ |
| 846 | static void msp34xxg_reset(struct i2c_client *client) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 847 | { |
| 848 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 849 | int modus; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 850 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 851 | /* initialize std to 1 (autodetect) to signal that no standard is |
| 852 | selected yet. */ |
| 853 | state->std = 1; |
| 854 | |
| 855 | msp_reset(client); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 856 | |
| 857 | /* make sure that input/output is muted (paranoid mode) */ |
| 858 | /* ACB, mute DSP input, mute SCART 1 */ |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 859 | msp_write_dsp(client, 0x13, 0x0f20); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 860 | |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 861 | if (state->has_i2s_conf) |
| 862 | msp_write_dem(client, 0x40, state->i2s_mode); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 863 | |
| 864 | /* step-by-step initialisation, as described in the manual */ |
Hans Verkuil | 9a80a93 | 2006-03-19 07:25:42 -0300 | [diff] [blame] | 865 | modus = msp34xxg_modus(client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 866 | msp_write_dem(client, 0x30, modus); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 867 | |
| 868 | /* write the dsps that may have an influence on |
| 869 | standard/audio autodetection right now */ |
| 870 | msp34xxg_set_source(client, state->source); |
| 871 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 872 | msp_write_dsp(client, 0x0d, 0x1900); /* scart */ |
| 873 | msp_write_dsp(client, 0x0e, 0x3000); /* FM */ |
| 874 | if (state->has_nicam) |
| 875 | msp_write_dsp(client, 0x10, 0x5a00); /* nicam */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 876 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 877 | /* set identification threshold. Personally, I |
| 878 | * I set it to a higher value than the default |
| 879 | * of 0x190 to ignore noisy stereo signals. |
| 880 | * this needs tuning. (recommended range 0x00a0-0x03c0) |
| 881 | * 0x7f0 = forced mono mode |
| 882 | * |
| 883 | * a2 threshold for stereo/bilingual. |
| 884 | * Note: this register is part of the Manual/Compatibility mode. |
| 885 | * It is supported by all 'G'-family chips. |
| 886 | */ |
| 887 | msp_write_dem(client, 0x22, msp_stereo_thresh); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | int msp34xxg_thread(void *data) |
| 891 | { |
| 892 | struct i2c_client *client = data; |
| 893 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 894 | int val, i; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 895 | |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 896 | v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 897 | |
| 898 | state->source = 1; /* default */ |
| 899 | for (;;) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 900 | v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 901 | msp_sleep(state, -1); |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 902 | v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 903 | |
| 904 | restart: |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 905 | v4l_dbg(1, msp_debug, client, "thread: restart scan\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 906 | state->restart = 0; |
| 907 | if (kthread_should_stop()) |
| 908 | break; |
| 909 | |
| 910 | /* setup the chip*/ |
| 911 | msp34xxg_reset(client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 912 | state->std = state->radio ? 0x40 : msp_standard; |
| 913 | if (state->std != 1) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 914 | goto unmute; |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 915 | /* start autodetect */ |
| 916 | msp_write_dem(client, 0x20, state->std); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 917 | |
| 918 | /* watch autodetect */ |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 919 | v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 920 | for (i = 0; i < 10; i++) { |
| 921 | if (msp_sleep(state, 100)) |
| 922 | goto restart; |
| 923 | |
| 924 | /* check results */ |
| 925 | val = msp_read_dem(client, 0x7e); |
| 926 | if (val < 0x07ff) { |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 927 | state->std = val; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 928 | break; |
| 929 | } |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 930 | v4l_dbg(2, msp_debug, client, "detection still in progress\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 931 | } |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 932 | if (state->std == 1) { |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 933 | v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 934 | continue; |
| 935 | } |
| 936 | |
| 937 | unmute: |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 938 | v4l_dbg(1, msp_debug, client, "detected standard: %s (0x%04x)\n", |
| 939 | msp_standard_std_name(state->std), state->std); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 940 | |
| 941 | /* unmute: dispatch sound to scart output, set scart volume */ |
| 942 | msp_set_audio(client); |
| 943 | |
| 944 | /* restore ACB */ |
| 945 | if (msp_write_dsp(client, 0x13, state->acb)) |
| 946 | return -1; |
| 947 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 948 | /* the periodic stereo/SAP check is only relevant for |
| 949 | the 0x20 standard (BTSC) */ |
| 950 | if (state->std != 0x20) |
| 951 | continue; |
| 952 | |
| 953 | state->watch_stereo = 1; |
| 954 | |
| 955 | /* monitor tv audio mode, the first time don't wait |
| 956 | in order to get a quick stereo/SAP update */ |
| 957 | watch_stereo(client); |
| 958 | while (state->watch_stereo) { |
| 959 | watch_stereo(client); |
| 960 | if (msp_sleep(state, 5000)) |
| 961 | goto restart; |
| 962 | } |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 963 | } |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 964 | v4l_dbg(1, msp_debug, client, "thread: exit\n"); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 965 | return 0; |
| 966 | } |
| 967 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 968 | static int msp34xxg_detect_stereo(struct i2c_client *client) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 969 | { |
| 970 | struct msp_state *state = i2c_get_clientdata(client); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 971 | int status = msp_read_dem(client, 0x0200); |
| 972 | int is_bilingual = status & 0x100; |
| 973 | int is_stereo = status & 0x40; |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 974 | int oldrx = state->rxsubchans; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 975 | |
| 976 | state->rxsubchans = 0; |
| 977 | if (is_stereo) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 978 | state->rxsubchans = V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 979 | else |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 980 | state->rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 981 | if (is_bilingual) { |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 982 | if (state->std == 0x20) |
| 983 | state->rxsubchans |= V4L2_TUNER_SUB_SAP; |
| 984 | else |
| 985 | state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 986 | } |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 987 | v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n", |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 988 | status, is_stereo, is_bilingual, state->rxsubchans); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 989 | return (oldrx != state->rxsubchans); |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 990 | } |
| 991 | |
Adrian Bunk | 044f324 | 2006-03-08 10:50:07 -0300 | [diff] [blame] | 992 | static void msp34xxg_set_audmode(struct i2c_client *client) |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 993 | { |
| 994 | struct msp_state *state = i2c_get_clientdata(client); |
| 995 | int source; |
| 996 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 997 | if (state->std == 0x20) { |
| 998 | if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) && |
| 999 | (state->audmode == V4L2_TUNER_MODE_STEREO || |
| 1000 | state->audmode == V4L2_TUNER_MODE_LANG2)) { |
| 1001 | msp_write_dem(client, 0x20, 0x21); |
| 1002 | } else { |
| 1003 | msp_write_dem(client, 0x20, 0x20); |
| 1004 | } |
| 1005 | } |
| 1006 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1007 | switch (state->audmode) { |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1008 | case V4L2_TUNER_MODE_MONO: |
| 1009 | source = 0; /* mono only */ |
| 1010 | break; |
| 1011 | case V4L2_TUNER_MODE_STEREO: |
| 1012 | source = 1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */ |
| 1013 | /* problem: that could also mean 2 (scart input) */ |
| 1014 | break; |
| 1015 | case V4L2_TUNER_MODE_LANG1: |
| 1016 | source = 3; /* stereo or A */ |
| 1017 | break; |
| 1018 | case V4L2_TUNER_MODE_LANG2: |
| 1019 | source = 4; /* stereo or B */ |
| 1020 | break; |
| 1021 | default: |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1022 | source = 1; |
| 1023 | break; |
| 1024 | } |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1025 | msp34xxg_set_source(client, source); |
| 1026 | } |
| 1027 | |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1028 | void msp_set_audmode(struct i2c_client *client) |
| 1029 | { |
| 1030 | struct msp_state *state = i2c_get_clientdata(client); |
| 1031 | |
| 1032 | switch (state->opmode) { |
| 1033 | case OPMODE_MANUAL: |
| 1034 | case OPMODE_AUTODETECT: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1035 | msp3400c_set_audmode(client); |
| 1036 | break; |
| 1037 | case OPMODE_AUTOSELECT: |
| 1038 | msp34xxg_set_audmode(client); |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 1043 | int msp_detect_stereo(struct i2c_client *client) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1044 | { |
| 1045 | struct msp_state *state = i2c_get_clientdata(client); |
| 1046 | |
| 1047 | switch (state->opmode) { |
| 1048 | case OPMODE_MANUAL: |
| 1049 | case OPMODE_AUTODETECT: |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 1050 | return msp3400c_detect_stereo(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1051 | case OPMODE_AUTOSELECT: |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 1052 | return msp34xxg_detect_stereo(client); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1053 | } |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame^] | 1054 | return 0; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 1055 | } |
| 1056 | |