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