msp3400-kthreads.c 32 KB

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