msp3400-kthreads.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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_PAL) {
  760. v4l_dbg(1, msp_debug, client, "selected PAL modus\n");
  761. return 0x7001;
  762. }
  763. if (state->v4l2_std == V4L2_STD_NTSC_M_JP) {
  764. v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n");
  765. return 0x4001;
  766. }
  767. if (state->v4l2_std == V4L2_STD_NTSC_M_KR) {
  768. v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n");
  769. return 0x0001;
  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. if (state->v4l2_std & V4L2_STD_SECAM) {
  776. v4l_dbg(1, msp_debug, client, "selected SECAM modus\n");
  777. return 0x6001;
  778. }
  779. return 0x0001;
  780. }
  781. static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
  782. {
  783. struct msp_state *state = i2c_get_clientdata(client);
  784. int source, matrix;
  785. switch (state->audmode) {
  786. case V4L2_TUNER_MODE_MONO:
  787. source = 0; /* mono only */
  788. matrix = 0x30;
  789. break;
  790. case V4L2_TUNER_MODE_LANG2:
  791. source = 4; /* stereo or B */
  792. matrix = 0x10;
  793. break;
  794. case V4L2_TUNER_MODE_LANG1_LANG2:
  795. source = 1; /* stereo or A|B */
  796. matrix = 0x20;
  797. break;
  798. case V4L2_TUNER_MODE_LANG1:
  799. source = 3; /* stereo or A */
  800. matrix = 0x00;
  801. break;
  802. case V4L2_TUNER_MODE_STEREO:
  803. default:
  804. source = 3; /* stereo or A */
  805. matrix = 0x20;
  806. break;
  807. }
  808. if (in == MSP_DSP_IN_TUNER)
  809. source = (source << 8) | 0x20;
  810. /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14
  811. instead of 11, 12, 13. So we add one for that msp version. */
  812. else if (in >= MSP_DSP_IN_MAIN_AVC && state->has_dolby_pro_logic)
  813. source = ((in + 1) << 8) | matrix;
  814. else
  815. source = (in << 8) | matrix;
  816. v4l_dbg(1, msp_debug, client,
  817. "set source to %d (0x%x) for output %02x\n", in, source, reg);
  818. msp_write_dsp(client, reg, source);
  819. }
  820. static void msp34xxg_set_sources(struct i2c_client *client)
  821. {
  822. struct msp_state *state = i2c_get_clientdata(client);
  823. u32 in = state->routing.input;
  824. msp34xxg_set_source(client, 0x0008, (in >> 4) & 0xf);
  825. /* quasi-peak detector is set to same input as the loudspeaker (MAIN) */
  826. msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf);
  827. msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf);
  828. msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf);
  829. if (state->has_scart2_out)
  830. msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf);
  831. msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf);
  832. }
  833. /* (re-)initialize the msp34xxg */
  834. static void msp34xxg_reset(struct i2c_client *client)
  835. {
  836. struct msp_state *state = i2c_get_clientdata(client);
  837. int tuner = (state->routing.input >> 3) & 1;
  838. int modus;
  839. /* initialize std to 1 (autodetect) to signal that no standard is
  840. selected yet. */
  841. state->std = 1;
  842. msp_reset(client);
  843. if (state->has_i2s_conf)
  844. msp_write_dem(client, 0x40, state->i2s_mode);
  845. /* step-by-step initialisation, as described in the manual */
  846. modus = msp34xxg_modus(client);
  847. modus |= tuner ? 0x100 : 0;
  848. msp_write_dem(client, 0x30, modus);
  849. /* write the dsps that may have an influence on
  850. standard/audio autodetection right now */
  851. msp34xxg_set_sources(client);
  852. msp_write_dsp(client, 0x0d, 0x1900); /* scart */
  853. msp_write_dsp(client, 0x0e, 0x3000); /* FM */
  854. if (state->has_nicam)
  855. msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
  856. /* set identification threshold. Personally, I
  857. * I set it to a higher value than the default
  858. * of 0x190 to ignore noisy stereo signals.
  859. * this needs tuning. (recommended range 0x00a0-0x03c0)
  860. * 0x7f0 = forced mono mode
  861. *
  862. * a2 threshold for stereo/bilingual.
  863. * Note: this register is part of the Manual/Compatibility mode.
  864. * It is supported by all 'G'-family chips.
  865. */
  866. msp_write_dem(client, 0x22, msp_stereo_thresh);
  867. }
  868. int msp34xxg_thread(void *data)
  869. {
  870. struct i2c_client *client = data;
  871. struct msp_state *state = i2c_get_clientdata(client);
  872. int val, i;
  873. v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n");
  874. set_freezable();
  875. for (;;) {
  876. v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n");
  877. msp_sleep(state, -1);
  878. v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n");
  879. restart:
  880. v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
  881. state->restart = 0;
  882. if (kthread_should_stop())
  883. break;
  884. if (state->mode == MSP_MODE_EXTERN) {
  885. /* no carrier scan needed, just unmute */
  886. v4l_dbg(1, msp_debug, client,
  887. "thread: no carrier scan\n");
  888. state->scan_in_progress = 0;
  889. msp_set_audio(client);
  890. continue;
  891. }
  892. /* setup the chip*/
  893. msp34xxg_reset(client);
  894. state->std = state->radio ? 0x40 :
  895. (state->force_btsc && msp_standard == 1) ? 32 : msp_standard;
  896. msp_write_dem(client, 0x20, state->std);
  897. /* start autodetect */
  898. if (state->std != 1)
  899. goto unmute;
  900. /* watch autodetect */
  901. v4l_dbg(1, msp_debug, client,
  902. "started autodetect, waiting for result\n");
  903. for (i = 0; i < 10; i++) {
  904. if (msp_sleep(state, 100))
  905. goto restart;
  906. /* check results */
  907. val = msp_read_dem(client, 0x7e);
  908. if (val < 0x07ff) {
  909. state->std = val;
  910. break;
  911. }
  912. v4l_dbg(2, msp_debug, client,
  913. "detection still in progress\n");
  914. }
  915. if (state->std == 1) {
  916. v4l_dbg(1, msp_debug, client,
  917. "detection still in progress after 10 tries. giving up.\n");
  918. continue;
  919. }
  920. unmute:
  921. v4l_dbg(1, msp_debug, client,
  922. "detected standard: %s (0x%04x)\n",
  923. msp_standard_std_name(state->std), state->std);
  924. if (state->std == 9) {
  925. /* AM NICAM mode */
  926. msp_write_dsp(client, 0x0e, 0x7c00);
  927. }
  928. /* unmute: dispatch sound to scart output, set scart volume */
  929. msp_set_audio(client);
  930. /* restore ACB */
  931. if (msp_write_dsp(client, 0x13, state->acb))
  932. return -1;
  933. /* the periodic stereo/SAP check is only relevant for
  934. the 0x20 standard (BTSC) */
  935. if (state->std != 0x20)
  936. continue;
  937. state->watch_stereo = 1;
  938. /* monitor tv audio mode, the first time don't wait
  939. in order to get a quick stereo/SAP update */
  940. watch_stereo(client);
  941. while (state->watch_stereo) {
  942. watch_stereo(client);
  943. if (msp_sleep(state, 5000))
  944. goto restart;
  945. }
  946. }
  947. v4l_dbg(1, msp_debug, client, "thread: exit\n");
  948. return 0;
  949. }
  950. static int msp34xxg_detect_stereo(struct i2c_client *client)
  951. {
  952. struct msp_state *state = i2c_get_clientdata(client);
  953. int status = msp_read_dem(client, 0x0200);
  954. int is_bilingual = status & 0x100;
  955. int is_stereo = status & 0x40;
  956. int oldrx = state->rxsubchans;
  957. if (state->mode == MSP_MODE_EXTERN)
  958. return 0;
  959. state->rxsubchans = 0;
  960. if (is_stereo)
  961. state->rxsubchans = V4L2_TUNER_SUB_STEREO;
  962. else
  963. state->rxsubchans = V4L2_TUNER_SUB_MONO;
  964. if (is_bilingual) {
  965. if (state->std == 0x20)
  966. state->rxsubchans |= V4L2_TUNER_SUB_SAP;
  967. else
  968. state->rxsubchans =
  969. V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  970. }
  971. v4l_dbg(1, msp_debug, client,
  972. "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
  973. status, is_stereo, is_bilingual, state->rxsubchans);
  974. return (oldrx != state->rxsubchans);
  975. }
  976. static void msp34xxg_set_audmode(struct i2c_client *client)
  977. {
  978. struct msp_state *state = i2c_get_clientdata(client);
  979. if (state->std == 0x20) {
  980. if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) &&
  981. (state->audmode == V4L2_TUNER_MODE_LANG1_LANG2 ||
  982. state->audmode == V4L2_TUNER_MODE_LANG2)) {
  983. msp_write_dem(client, 0x20, 0x21);
  984. } else {
  985. msp_write_dem(client, 0x20, 0x20);
  986. }
  987. }
  988. msp34xxg_set_sources(client);
  989. }
  990. void msp_set_audmode(struct i2c_client *client)
  991. {
  992. struct msp_state *state = i2c_get_clientdata(client);
  993. switch (state->opmode) {
  994. case OPMODE_MANUAL:
  995. case OPMODE_AUTODETECT:
  996. msp3400c_set_audmode(client);
  997. break;
  998. case OPMODE_AUTOSELECT:
  999. msp34xxg_set_audmode(client);
  1000. break;
  1001. }
  1002. }
  1003. int msp_detect_stereo(struct i2c_client *client)
  1004. {
  1005. struct msp_state *state = i2c_get_clientdata(client);
  1006. switch (state->opmode) {
  1007. case OPMODE_MANUAL:
  1008. case OPMODE_AUTODETECT:
  1009. return msp3400c_detect_stereo(client);
  1010. case OPMODE_AUTOSELECT:
  1011. return msp34xxg_detect_stereo(client);
  1012. }
  1013. return 0;
  1014. }