msp3400-kthreads.c 32 KB

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