msp3400-kthreads.c 32 KB

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