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