msp3400-kthreads.c 32 KB

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