msp3400-kthreads.c 32 KB

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