msp3400-driver.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * Programming the mspx4xx sound processor family
  3. *
  4. * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org>
  5. *
  6. * what works and what doesn't:
  7. *
  8. * AM-Mono
  9. * Support for Hauppauge cards added (decoding handled by tuner) added by
  10. * Frederic Crozat <fcrozat@mail.dotcom.fr>
  11. *
  12. * FM-Mono
  13. * should work. The stereo modes are backward compatible to FM-mono,
  14. * therefore FM-Mono should be allways available.
  15. *
  16. * FM-Stereo (B/G, used in germany)
  17. * should work, with autodetect
  18. *
  19. * FM-Stereo (satellite)
  20. * should work, no autodetect (i.e. default is mono, but you can
  21. * switch to stereo -- untested)
  22. *
  23. * NICAM (B/G, L , used in UK, Scandinavia, Spain and France)
  24. * should work, with autodetect. Support for NICAM was added by
  25. * Pekka Pietikainen <pp@netppl.fi>
  26. *
  27. * TODO:
  28. * - better SAT support
  29. *
  30. * 980623 Thomas Sailer (sailer@ife.ee.ethz.ch)
  31. * using soundcore instead of OSS
  32. *
  33. * This program is free software; you can redistribute it and/or
  34. * modify it under the terms of the GNU General Public License
  35. * as published by the Free Software Foundation; either version 2
  36. * of the License, or (at your option) any later version.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU General Public License
  44. * along with this program; if not, write to the Free Software
  45. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  46. */
  47. #include <linux/kernel.h>
  48. #include <linux/module.h>
  49. #include <linux/slab.h>
  50. #include <linux/i2c.h>
  51. #include <linux/videodev.h>
  52. #include <linux/videodev2.h>
  53. #include <media/v4l2-common.h>
  54. #include <media/audiochip.h>
  55. #include <linux/kthread.h>
  56. #include <linux/suspend.h>
  57. #include "msp3400.h"
  58. /* ---------------------------------------------------------------------- */
  59. MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
  60. MODULE_AUTHOR("Gerd Knorr");
  61. MODULE_LICENSE("GPL");
  62. /* module parameters */
  63. static int opmode = OPMODE_AUTO;
  64. int msp_debug; /* msp_debug output */
  65. int msp_once; /* no continous stereo monitoring */
  66. int msp_amsound; /* hard-wire AM sound at 6.5 Hz (france),
  67. the autoscan seems work well only with FM... */
  68. int msp_standard = 1; /* Override auto detect of audio msp_standard, if needed. */
  69. int msp_dolby;
  70. int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual
  71. (msp34xxg only) 0x00a0-0x03c0 */
  72. /* read-only */
  73. module_param(opmode, int, 0444);
  74. /* read-write */
  75. module_param_named(once,msp_once, bool, 0644);
  76. module_param_named(debug,msp_debug, int, 0644);
  77. module_param_named(stereo_threshold,msp_stereo_thresh, int, 0644);
  78. module_param_named(standard,msp_standard, int, 0644);
  79. module_param_named(amsound,msp_amsound, bool, 0644);
  80. module_param_named(dolby,msp_dolby, bool, 0644);
  81. MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
  82. MODULE_PARM_DESC(once, "No continuous stereo monitoring");
  83. MODULE_PARM_DESC(debug, "Enable debug messages [0-3]");
  84. MODULE_PARM_DESC(stereo_threshold, "Sets signal threshold to activate stereo");
  85. MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
  86. MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
  87. MODULE_PARM_DESC(dolby, "Activates Dolby processsing");
  88. /* ---------------------------------------------------------------------- */
  89. /* control subaddress */
  90. #define I2C_MSP_CONTROL 0x00
  91. /* demodulator unit subaddress */
  92. #define I2C_MSP_DEM 0x10
  93. /* DSP unit subaddress */
  94. #define I2C_MSP_DSP 0x12
  95. /* Addresses to scan */
  96. static unsigned short normal_i2c[] = { 0x80 >> 1, 0x88 >> 1, I2C_CLIENT_END };
  97. I2C_CLIENT_INSMOD;
  98. /* ----------------------------------------------------------------------- */
  99. /* functions for talking to the MSP3400C Sound processor */
  100. int msp_reset(struct i2c_client *client)
  101. {
  102. /* reset and read revision code */
  103. static u8 reset_off[3] = { I2C_MSP_CONTROL, 0x80, 0x00 };
  104. static u8 reset_on[3] = { I2C_MSP_CONTROL, 0x00, 0x00 };
  105. static u8 write[3] = { I2C_MSP_DSP + 1, 0x00, 0x1e };
  106. u8 read[2];
  107. struct i2c_msg reset[2] = {
  108. { client->addr, I2C_M_IGNORE_NAK, 3, reset_off },
  109. { client->addr, I2C_M_IGNORE_NAK, 3, reset_on },
  110. };
  111. struct i2c_msg test[2] = {
  112. { client->addr, 0, 3, write },
  113. { client->addr, I2C_M_RD, 2, read },
  114. };
  115. v4l_dbg(3, msp_debug, client, "msp_reset\n");
  116. if (i2c_transfer(client->adapter, &reset[0], 1) != 1 ||
  117. i2c_transfer(client->adapter, &reset[1], 1) != 1 ||
  118. i2c_transfer(client->adapter, test, 2) != 2) {
  119. v4l_err(client, "chip reset failed\n");
  120. return -1;
  121. }
  122. return 0;
  123. }
  124. static int msp_read(struct i2c_client *client, int dev, int addr)
  125. {
  126. int err, retval;
  127. u8 write[3];
  128. u8 read[2];
  129. struct i2c_msg msgs[2] = {
  130. { client->addr, 0, 3, write },
  131. { client->addr, I2C_M_RD, 2, read }
  132. };
  133. write[0] = dev + 1;
  134. write[1] = addr >> 8;
  135. write[2] = addr & 0xff;
  136. for (err = 0; err < 3; err++) {
  137. if (i2c_transfer(client->adapter, msgs, 2) == 2)
  138. break;
  139. v4l_warn(client, "I/O error #%d (read 0x%02x/0x%02x)\n", err,
  140. dev, addr);
  141. current->state = TASK_INTERRUPTIBLE;
  142. schedule_timeout(msecs_to_jiffies(10));
  143. }
  144. if (err == 3) {
  145. v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n");
  146. msp_reset(client);
  147. return -1;
  148. }
  149. retval = read[0] << 8 | read[1];
  150. v4l_dbg(3, msp_debug, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
  151. return retval;
  152. }
  153. int msp_read_dem(struct i2c_client *client, int addr)
  154. {
  155. return msp_read(client, I2C_MSP_DEM, addr);
  156. }
  157. int msp_read_dsp(struct i2c_client *client, int addr)
  158. {
  159. return msp_read(client, I2C_MSP_DSP, addr);
  160. }
  161. static int msp_write(struct i2c_client *client, int dev, int addr, int val)
  162. {
  163. int err;
  164. u8 buffer[5];
  165. buffer[0] = dev;
  166. buffer[1] = addr >> 8;
  167. buffer[2] = addr & 0xff;
  168. buffer[3] = val >> 8;
  169. buffer[4] = val & 0xff;
  170. v4l_dbg(3, msp_debug, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
  171. for (err = 0; err < 3; err++) {
  172. if (i2c_master_send(client, buffer, 5) == 5)
  173. break;
  174. v4l_warn(client, "I/O error #%d (write 0x%02x/0x%02x)\n", err,
  175. dev, addr);
  176. current->state = TASK_INTERRUPTIBLE;
  177. schedule_timeout(msecs_to_jiffies(10));
  178. }
  179. if (err == 3) {
  180. v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n");
  181. msp_reset(client);
  182. return -1;
  183. }
  184. return 0;
  185. }
  186. int msp_write_dem(struct i2c_client *client, int addr, int val)
  187. {
  188. return msp_write(client, I2C_MSP_DEM, addr, val);
  189. }
  190. int msp_write_dsp(struct i2c_client *client, int addr, int val)
  191. {
  192. return msp_write(client, I2C_MSP_DSP, addr, val);
  193. }
  194. /* ----------------------------------------------------------------------- *
  195. * bits 9 8 5 - SCART DSP input Select:
  196. * 0 0 0 - SCART 1 to DSP input (reset position)
  197. * 0 1 0 - MONO to DSP input
  198. * 1 0 0 - SCART 2 to DSP input
  199. * 1 1 1 - Mute DSP input
  200. *
  201. * bits 11 10 6 - SCART 1 Output Select:
  202. * 0 0 0 - undefined (reset position)
  203. * 0 1 0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS)
  204. * 1 0 0 - MONO input to SCART 1 Output
  205. * 1 1 0 - SCART 1 DA to SCART 1 Output
  206. * 0 0 1 - SCART 2 DA to SCART 1 Output
  207. * 0 1 1 - SCART 1 Input to SCART 1 Output
  208. * 1 1 1 - Mute SCART 1 Output
  209. *
  210. * bits 13 12 7 - SCART 2 Output Select (for devices with 2 Output SCART):
  211. * 0 0 0 - SCART 1 DA to SCART 2 Output (reset position)
  212. * 0 1 0 - SCART 1 Input to SCART 2 Output
  213. * 1 0 0 - MONO input to SCART 2 Output
  214. * 0 0 1 - SCART 2 DA to SCART 2 Output
  215. * 0 1 1 - SCART 2 Input to SCART 2 Output
  216. * 1 1 0 - Mute SCART 2 Output
  217. *
  218. * Bits 4 to 0 should be zero.
  219. * ----------------------------------------------------------------------- */
  220. static int scarts[3][9] = {
  221. /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */
  222. /* SCART DSP Input select */
  223. { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 },
  224. /* SCART1 Output select */
  225. { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
  226. /* SCART2 Output select */
  227. { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
  228. };
  229. static char *scart_names[] = {
  230. "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"
  231. };
  232. void msp_set_scart(struct i2c_client *client, int in, int out)
  233. {
  234. struct msp_state *state = i2c_get_clientdata(client);
  235. state->in_scart=in;
  236. if (in >= 1 && in <= 8 && out >= 0 && out <= 2) {
  237. if (-1 == scarts[out][in])
  238. return;
  239. state->acb &= ~scarts[out][SCART_MASK];
  240. state->acb |= scarts[out][in];
  241. } else
  242. state->acb = 0xf60; /* Mute Input and SCART 1 Output */
  243. v4l_dbg(1, msp_debug, client, "scart switch: %s => %d (ACB=0x%04x)\n",
  244. scart_names[in], out, state->acb);
  245. msp_write_dsp(client, 0x13, state->acb);
  246. /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
  247. msp_write_dem(client, 0x40, state->i2s_mode);
  248. }
  249. void msp_set_mute(struct i2c_client *client)
  250. {
  251. struct msp_state *state = i2c_get_clientdata(client);
  252. v4l_dbg(1, msp_debug, client, "mute audio\n");
  253. msp_write_dsp(client, 0x0000, 0);
  254. msp_write_dsp(client, 0x0007, 1);
  255. if (state->has_scart2_out_volume)
  256. msp_write_dsp(client, 0x0040, 1);
  257. if (state->has_headphones)
  258. msp_write_dsp(client, 0x0006, 0);
  259. }
  260. void msp_set_audio(struct i2c_client *client)
  261. {
  262. struct msp_state *state = i2c_get_clientdata(client);
  263. int bal = 0, bass, treble, loudness;
  264. int val = 0;
  265. if (!state->muted)
  266. val = (state->volume * 0x7f / 65535) << 8;
  267. v4l_dbg(1, msp_debug, client, "mute=%s volume=%d\n",
  268. state->muted ? "on" : "off", state->volume);
  269. msp_write_dsp(client, 0x0000, val);
  270. msp_write_dsp(client, 0x0007, state->muted ? 0x1 : (val | 0x1));
  271. if (state->has_scart2_out_volume)
  272. msp_write_dsp(client, 0x0040, state->muted ? 0x1 : (val | 0x1));
  273. if (state->has_headphones)
  274. msp_write_dsp(client, 0x0006, val);
  275. if (!state->has_sound_processing)
  276. return;
  277. if (val)
  278. bal = (u8)((state->balance / 256) - 128);
  279. bass = ((state->bass - 32768) * 0x60 / 65535) << 8;
  280. treble = ((state->treble - 32768) * 0x60 / 65535) << 8;
  281. loudness = state->loudness ? ((5 * 4) << 8) : 0;
  282. v4l_dbg(1, msp_debug, client, "balance=%d bass=%d treble=%d loudness=%d\n",
  283. state->balance, state->bass, state->treble, state->loudness);
  284. msp_write_dsp(client, 0x0001, bal << 8);
  285. msp_write_dsp(client, 0x0002, bass);
  286. msp_write_dsp(client, 0x0003, treble);
  287. msp_write_dsp(client, 0x0004, loudness);
  288. if (!state->has_headphones)
  289. return;
  290. msp_write_dsp(client, 0x0030, bal << 8);
  291. msp_write_dsp(client, 0x0031, bass);
  292. msp_write_dsp(client, 0x0032, treble);
  293. msp_write_dsp(client, 0x0033, loudness);
  294. }
  295. int msp_modus(struct i2c_client *client)
  296. {
  297. struct msp_state *state = i2c_get_clientdata(client);
  298. if (state->radio) {
  299. v4l_dbg(1, msp_debug, client, "video mode selected to Radio\n");
  300. return 0x0003;
  301. }
  302. if (state->v4l2_std & V4L2_STD_PAL) {
  303. v4l_dbg(1, msp_debug, client, "video mode selected to PAL\n");
  304. #if 1
  305. /* experimental: not sure this works with all chip versions */
  306. return 0x7003;
  307. #else
  308. /* previous value, try this if it breaks ... */
  309. return 0x1003;
  310. #endif
  311. }
  312. if (state->v4l2_std & V4L2_STD_NTSC) {
  313. v4l_dbg(1, msp_debug, client, "video mode selected to NTSC\n");
  314. return 0x2003;
  315. }
  316. if (state->v4l2_std & V4L2_STD_SECAM) {
  317. v4l_dbg(1, msp_debug, client, "video mode selected to SECAM\n");
  318. return 0x0003;
  319. }
  320. return 0x0003;
  321. }
  322. /* ------------------------------------------------------------------------ */
  323. static void msp_wake_thread(struct i2c_client *client)
  324. {
  325. struct msp_state *state = i2c_get_clientdata(client);
  326. if (NULL == state->kthread)
  327. return;
  328. msp_set_mute(client);
  329. state->watch_stereo = 0;
  330. state->restart = 1;
  331. wake_up_interruptible(&state->wq);
  332. }
  333. int msp_sleep(struct msp_state *state, int timeout)
  334. {
  335. DECLARE_WAITQUEUE(wait, current);
  336. add_wait_queue(&state->wq, &wait);
  337. if (!kthread_should_stop()) {
  338. if (timeout < 0) {
  339. set_current_state(TASK_INTERRUPTIBLE);
  340. schedule();
  341. } else {
  342. schedule_timeout_interruptible
  343. (msecs_to_jiffies(timeout));
  344. }
  345. }
  346. remove_wait_queue(&state->wq, &wait);
  347. try_to_freeze();
  348. return state->restart;
  349. }
  350. /* ------------------------------------------------------------------------ */
  351. static int msp_mode_v4l2_to_v4l1(int rxsubchans)
  352. {
  353. int mode = 0;
  354. if (rxsubchans & V4L2_TUNER_SUB_STEREO)
  355. mode |= VIDEO_SOUND_STEREO;
  356. if (rxsubchans & V4L2_TUNER_SUB_LANG2)
  357. mode |= VIDEO_SOUND_LANG2;
  358. if (rxsubchans & V4L2_TUNER_SUB_LANG1)
  359. mode |= VIDEO_SOUND_LANG1;
  360. if (mode == 0)
  361. mode |= VIDEO_SOUND_MONO;
  362. return mode;
  363. }
  364. static int msp_mode_v4l1_to_v4l2(int mode)
  365. {
  366. if (mode & VIDEO_SOUND_STEREO)
  367. return V4L2_TUNER_MODE_STEREO;
  368. if (mode & VIDEO_SOUND_LANG2)
  369. return V4L2_TUNER_MODE_LANG2;
  370. if (mode & VIDEO_SOUND_LANG1)
  371. return V4L2_TUNER_MODE_LANG1;
  372. return V4L2_TUNER_MODE_MONO;
  373. }
  374. static void msp_any_detect_stereo(struct i2c_client *client)
  375. {
  376. struct msp_state *state = i2c_get_clientdata(client);
  377. switch (state->opmode) {
  378. case OPMODE_MANUAL:
  379. case OPMODE_AUTODETECT:
  380. autodetect_stereo(client);
  381. break;
  382. case OPMODE_AUTOSELECT:
  383. msp34xxg_detect_stereo(client);
  384. break;
  385. }
  386. }
  387. static struct v4l2_queryctrl msp_qctrl_std[] = {
  388. {
  389. .id = V4L2_CID_AUDIO_VOLUME,
  390. .name = "Volume",
  391. .minimum = 0,
  392. .maximum = 65535,
  393. .step = 65535/100,
  394. .default_value = 58880,
  395. .flags = 0,
  396. .type = V4L2_CTRL_TYPE_INTEGER,
  397. },{
  398. .id = V4L2_CID_AUDIO_MUTE,
  399. .name = "Mute",
  400. .minimum = 0,
  401. .maximum = 1,
  402. .step = 1,
  403. .default_value = 1,
  404. .flags = 0,
  405. .type = V4L2_CTRL_TYPE_BOOLEAN,
  406. },
  407. };
  408. static struct v4l2_queryctrl msp_qctrl_sound_processing[] = {
  409. {
  410. .id = V4L2_CID_AUDIO_BALANCE,
  411. .name = "Balance",
  412. .minimum = 0,
  413. .maximum = 65535,
  414. .step = 65535/100,
  415. .default_value = 32768,
  416. .flags = 0,
  417. .type = V4L2_CTRL_TYPE_INTEGER,
  418. },{
  419. .id = V4L2_CID_AUDIO_BASS,
  420. .name = "Bass",
  421. .minimum = 0,
  422. .maximum = 65535,
  423. .step = 65535/100,
  424. .default_value = 32768,
  425. .type = V4L2_CTRL_TYPE_INTEGER,
  426. },{
  427. .id = V4L2_CID_AUDIO_TREBLE,
  428. .name = "Treble",
  429. .minimum = 0,
  430. .maximum = 65535,
  431. .step = 65535/100,
  432. .default_value = 32768,
  433. .type = V4L2_CTRL_TYPE_INTEGER,
  434. },{
  435. .id = V4L2_CID_AUDIO_LOUDNESS,
  436. .name = "Loudness",
  437. .minimum = 0,
  438. .maximum = 1,
  439. .step = 1,
  440. .default_value = 1,
  441. .flags = 0,
  442. .type = V4L2_CTRL_TYPE_BOOLEAN,
  443. },
  444. };
  445. static void msp_any_set_audmode(struct i2c_client *client, int audmode)
  446. {
  447. struct msp_state *state = i2c_get_clientdata(client);
  448. switch (state->opmode) {
  449. case OPMODE_MANUAL:
  450. case OPMODE_AUTODETECT:
  451. state->watch_stereo = 0;
  452. msp3400c_setstereo(client, audmode);
  453. break;
  454. case OPMODE_AUTOSELECT:
  455. msp34xxg_set_audmode(client, audmode);
  456. break;
  457. }
  458. }
  459. static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  460. {
  461. struct msp_state *state = i2c_get_clientdata(client);
  462. switch (ctrl->id) {
  463. case V4L2_CID_AUDIO_VOLUME:
  464. ctrl->value = state->volume;
  465. break;
  466. case V4L2_CID_AUDIO_MUTE:
  467. ctrl->value = state->muted;
  468. break;
  469. case V4L2_CID_AUDIO_BALANCE:
  470. if (!state->has_sound_processing)
  471. return -EINVAL;
  472. ctrl->value = state->balance;
  473. break;
  474. case V4L2_CID_AUDIO_BASS:
  475. if (!state->has_sound_processing)
  476. return -EINVAL;
  477. ctrl->value = state->bass;
  478. break;
  479. case V4L2_CID_AUDIO_TREBLE:
  480. if (!state->has_sound_processing)
  481. return -EINVAL;
  482. ctrl->value = state->treble;
  483. break;
  484. case V4L2_CID_AUDIO_LOUDNESS:
  485. if (!state->has_sound_processing)
  486. return -EINVAL;
  487. ctrl->value = state->loudness;
  488. break;
  489. default:
  490. return -EINVAL;
  491. }
  492. return 0;
  493. }
  494. static int msp_set_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  495. {
  496. struct msp_state *state = i2c_get_clientdata(client);
  497. switch (ctrl->id) {
  498. case V4L2_CID_AUDIO_VOLUME:
  499. state->volume = ctrl->value;
  500. if (state->volume == 0)
  501. state->balance = 32768;
  502. break;
  503. case V4L2_CID_AUDIO_MUTE:
  504. if (ctrl->value < 0 || ctrl->value >= 2)
  505. return -ERANGE;
  506. state->muted = ctrl->value;
  507. break;
  508. case V4L2_CID_AUDIO_BASS:
  509. if (!state->has_sound_processing)
  510. return -EINVAL;
  511. state->bass = ctrl->value;
  512. break;
  513. case V4L2_CID_AUDIO_TREBLE:
  514. if (!state->has_sound_processing)
  515. return -EINVAL;
  516. state->treble = ctrl->value;
  517. break;
  518. case V4L2_CID_AUDIO_LOUDNESS:
  519. if (!state->has_sound_processing)
  520. return -EINVAL;
  521. state->loudness = ctrl->value;
  522. break;
  523. case V4L2_CID_AUDIO_BALANCE:
  524. if (!state->has_sound_processing)
  525. return -EINVAL;
  526. state->balance = ctrl->value;
  527. break;
  528. default:
  529. return -EINVAL;
  530. }
  531. msp_set_audio(client);
  532. return 0;
  533. }
  534. static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
  535. {
  536. struct msp_state *state = i2c_get_clientdata(client);
  537. u16 *sarg = arg;
  538. int scart = 0;
  539. if (msp_debug >= 2)
  540. v4l_i2c_print_ioctl(client, cmd);
  541. switch (cmd) {
  542. case AUDC_SET_INPUT:
  543. if (*sarg == state->input)
  544. break;
  545. state->input = *sarg;
  546. switch (*sarg) {
  547. case AUDIO_RADIO:
  548. /* Hauppauge uses IN2 for the radio */
  549. state->mode = MSP_MODE_FM_RADIO;
  550. scart = SCART_IN2;
  551. break;
  552. case AUDIO_EXTERN_1:
  553. /* IN1 is often used for external input ... */
  554. state->mode = MSP_MODE_EXTERN;
  555. scart = SCART_IN1;
  556. break;
  557. case AUDIO_EXTERN_2:
  558. /* ... sometimes it is IN2 through ;) */
  559. state->mode = MSP_MODE_EXTERN;
  560. scart = SCART_IN2;
  561. break;
  562. case AUDIO_TUNER:
  563. state->mode = -1;
  564. break;
  565. default:
  566. if (*sarg & AUDIO_MUTE)
  567. msp_set_scart(client, SCART_MUTE, 0);
  568. break;
  569. }
  570. if (scart) {
  571. state->rxsubchans = V4L2_TUNER_SUB_STEREO;
  572. state->audmode = V4L2_TUNER_MODE_STEREO;
  573. msp_set_scart(client, scart, 0);
  574. msp_write_dsp(client, 0x000d, 0x1900);
  575. if (state->opmode != OPMODE_AUTOSELECT)
  576. msp3400c_setstereo(client, state->audmode);
  577. }
  578. msp_wake_thread(client);
  579. break;
  580. case AUDC_SET_RADIO:
  581. if (state->radio)
  582. return 0;
  583. state->radio = 1;
  584. v4l_dbg(1, msp_debug, client, "switching to radio mode\n");
  585. state->watch_stereo = 0;
  586. switch (state->opmode) {
  587. case OPMODE_MANUAL:
  588. /* set msp3400 to FM radio mode */
  589. msp3400c_setmode(client, MSP_MODE_FM_RADIO);
  590. msp3400c_setcarrier(client, MSP_CARRIER(10.7),
  591. MSP_CARRIER(10.7));
  592. msp_set_audio(client);
  593. break;
  594. case OPMODE_AUTODETECT:
  595. case OPMODE_AUTOSELECT:
  596. /* the thread will do for us */
  597. msp_wake_thread(client);
  598. break;
  599. }
  600. break;
  601. /* --- v4l ioctls --- */
  602. /* take care: bttv does userspace copying, we'll get a
  603. kernel pointer here... */
  604. case VIDIOCGAUDIO:
  605. {
  606. struct video_audio *va = arg;
  607. va->flags |= VIDEO_AUDIO_VOLUME | VIDEO_AUDIO_MUTABLE;
  608. if (state->has_sound_processing)
  609. va->flags |= VIDEO_AUDIO_BALANCE |
  610. VIDEO_AUDIO_BASS |
  611. VIDEO_AUDIO_TREBLE;
  612. if (state->muted)
  613. va->flags |= VIDEO_AUDIO_MUTE;
  614. va->volume = state->volume;
  615. va->balance = state->volume ? state->balance : 32768;
  616. va->bass = state->bass;
  617. va->treble = state->treble;
  618. if (state->radio)
  619. break;
  620. if (state->opmode == OPMODE_AUTOSELECT)
  621. msp_any_detect_stereo(client);
  622. va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans);
  623. break;
  624. }
  625. case VIDIOCSAUDIO:
  626. {
  627. struct video_audio *va = arg;
  628. state->muted = (va->flags & VIDEO_AUDIO_MUTE);
  629. state->volume = va->volume;
  630. state->balance = va->balance;
  631. state->bass = va->bass;
  632. state->treble = va->treble;
  633. msp_set_audio(client);
  634. if (va->mode != 0 && state->radio == 0)
  635. msp_any_set_audmode(client, msp_mode_v4l1_to_v4l2(va->mode));
  636. break;
  637. }
  638. case VIDIOCSCHAN:
  639. {
  640. struct video_channel *vc = arg;
  641. int update = 0;
  642. v4l2_std_id std;
  643. if (state->radio)
  644. update = 1;
  645. state->radio = 0;
  646. if (vc->norm == VIDEO_MODE_PAL)
  647. std = V4L2_STD_PAL;
  648. else if (vc->norm == VIDEO_MODE_SECAM)
  649. std = V4L2_STD_SECAM;
  650. else
  651. std = V4L2_STD_NTSC;
  652. if (std != state->v4l2_std) {
  653. state->v4l2_std = std;
  654. update = 1;
  655. }
  656. if (update)
  657. msp_wake_thread(client);
  658. break;
  659. }
  660. case VIDIOCSFREQ:
  661. case VIDIOC_S_FREQUENCY:
  662. {
  663. /* new channel -- kick audio carrier scan */
  664. msp_wake_thread(client);
  665. break;
  666. }
  667. /* msp34xx specific */
  668. case MSP_SET_MATRIX:
  669. {
  670. struct msp_matrix *mspm = arg;
  671. msp_set_scart(client, mspm->input, mspm->output);
  672. break;
  673. }
  674. /* --- v4l2 ioctls --- */
  675. case VIDIOC_S_STD:
  676. {
  677. v4l2_std_id *id = arg;
  678. int update = state->radio || state->v4l2_std != *id;
  679. state->v4l2_std = *id;
  680. state->radio = 0;
  681. if (update)
  682. msp_wake_thread(client);
  683. return 0;
  684. }
  685. case VIDIOC_ENUMINPUT:
  686. {
  687. struct v4l2_input *i = arg;
  688. if (i->index != 0)
  689. return -EINVAL;
  690. i->type = V4L2_INPUT_TYPE_TUNER;
  691. switch (i->index) {
  692. case AUDIO_RADIO:
  693. strcpy(i->name, "Radio");
  694. break;
  695. case AUDIO_EXTERN_1:
  696. strcpy(i->name, "Extern 1");
  697. break;
  698. case AUDIO_EXTERN_2:
  699. strcpy(i->name, "Extern 2");
  700. break;
  701. case AUDIO_TUNER:
  702. strcpy(i->name, "Television");
  703. break;
  704. default:
  705. return -EINVAL;
  706. }
  707. return 0;
  708. }
  709. case VIDIOC_G_AUDIO:
  710. {
  711. struct v4l2_audio *a = arg;
  712. memset(a, 0, sizeof(*a));
  713. switch (a->index) {
  714. case AUDIO_RADIO:
  715. strcpy(a->name, "Radio");
  716. break;
  717. case AUDIO_EXTERN_1:
  718. strcpy(a->name, "Extern 1");
  719. break;
  720. case AUDIO_EXTERN_2:
  721. strcpy(a->name, "Extern 2");
  722. break;
  723. case AUDIO_TUNER:
  724. strcpy(a->name, "Television");
  725. break;
  726. default:
  727. return -EINVAL;
  728. }
  729. msp_any_detect_stereo(client);
  730. if (state->audmode == V4L2_TUNER_MODE_STEREO) {
  731. a->capability = V4L2_AUDCAP_STEREO;
  732. }
  733. break;
  734. }
  735. case VIDIOC_S_AUDIO:
  736. {
  737. struct v4l2_audio *sarg = arg;
  738. switch (sarg->index) {
  739. case AUDIO_RADIO:
  740. /* Hauppauge uses IN2 for the radio */
  741. state->mode = MSP_MODE_FM_RADIO;
  742. scart = SCART_IN2;
  743. break;
  744. case AUDIO_EXTERN_1:
  745. /* IN1 is often used for external input ... */
  746. state->mode = MSP_MODE_EXTERN;
  747. scart = SCART_IN1;
  748. break;
  749. case AUDIO_EXTERN_2:
  750. /* ... sometimes it is IN2 through ;) */
  751. state->mode = MSP_MODE_EXTERN;
  752. scart = SCART_IN2;
  753. break;
  754. case AUDIO_TUNER:
  755. state->mode = -1;
  756. break;
  757. }
  758. if (scart) {
  759. state->rxsubchans = V4L2_TUNER_SUB_STEREO;
  760. state->audmode = V4L2_TUNER_MODE_STEREO;
  761. msp_set_scart(client, scart, 0);
  762. msp_write_dsp(client, 0x000d, 0x1900);
  763. }
  764. if (sarg->capability == V4L2_AUDCAP_STEREO) {
  765. state->audmode = V4L2_TUNER_MODE_STEREO;
  766. } else {
  767. state->audmode &= ~V4L2_TUNER_MODE_STEREO;
  768. }
  769. msp_any_set_audmode(client, state->audmode);
  770. msp_wake_thread(client);
  771. break;
  772. }
  773. case VIDIOC_G_TUNER:
  774. {
  775. struct v4l2_tuner *vt = arg;
  776. if (state->radio)
  777. break;
  778. if (state->opmode == OPMODE_AUTOSELECT)
  779. msp_any_detect_stereo(client);
  780. vt->audmode = state->audmode;
  781. vt->rxsubchans = state->rxsubchans;
  782. vt->capability = V4L2_TUNER_CAP_STEREO |
  783. V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
  784. break;
  785. }
  786. case VIDIOC_S_TUNER:
  787. {
  788. struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
  789. if (state->radio)
  790. break;
  791. /* only set audmode */
  792. if (vt->audmode != -1 && vt->audmode != 0)
  793. msp_any_set_audmode(client, vt->audmode);
  794. break;
  795. }
  796. case VIDIOC_G_AUDOUT:
  797. {
  798. struct v4l2_audioout *a = (struct v4l2_audioout *)arg;
  799. int idx = a->index;
  800. memset(a, 0, sizeof(*a));
  801. switch (idx) {
  802. case 0:
  803. strcpy(a->name, "Scart1 Out");
  804. break;
  805. case 1:
  806. strcpy(a->name, "Scart2 Out");
  807. break;
  808. case 2:
  809. strcpy(a->name, "I2S Out");
  810. break;
  811. default:
  812. return -EINVAL;
  813. }
  814. break;
  815. }
  816. case VIDIOC_S_AUDOUT:
  817. {
  818. struct v4l2_audioout *a = (struct v4l2_audioout *)arg;
  819. if (a->index < 0 || a->index > 2)
  820. return -EINVAL;
  821. v4l_dbg(1, msp_debug, client, "Setting audio out on msp34xx to input %i\n", a->index);
  822. msp_set_scart(client, state->in_scart, a->index + 1);
  823. break;
  824. }
  825. case VIDIOC_INT_I2S_CLOCK_FREQ:
  826. {
  827. u32 *a = (u32 *)arg;
  828. v4l_dbg(1, msp_debug, client, "Setting I2S speed to %d\n", *a);
  829. switch (*a) {
  830. case 1024000:
  831. state->i2s_mode = 0;
  832. break;
  833. case 2048000:
  834. state->i2s_mode = 1;
  835. break;
  836. default:
  837. return -EINVAL;
  838. }
  839. break;
  840. }
  841. case VIDIOC_QUERYCTRL:
  842. {
  843. struct v4l2_queryctrl *qc = arg;
  844. int i;
  845. for (i = 0; i < ARRAY_SIZE(msp_qctrl_std); i++)
  846. if (qc->id && qc->id == msp_qctrl_std[i].id) {
  847. memcpy(qc, &msp_qctrl_std[i], sizeof(*qc));
  848. return 0;
  849. }
  850. if (!state->has_sound_processing)
  851. return -EINVAL;
  852. for (i = 0; i < ARRAY_SIZE(msp_qctrl_sound_processing); i++)
  853. if (qc->id && qc->id == msp_qctrl_sound_processing[i].id) {
  854. memcpy(qc, &msp_qctrl_sound_processing[i], sizeof(*qc));
  855. return 0;
  856. }
  857. return -EINVAL;
  858. }
  859. case VIDIOC_G_CTRL:
  860. return msp_get_ctrl(client, arg);
  861. case VIDIOC_S_CTRL:
  862. return msp_set_ctrl(client, arg);
  863. case VIDIOC_LOG_STATUS:
  864. {
  865. const char *p;
  866. if (state->opmode == OPMODE_AUTOSELECT)
  867. msp_any_detect_stereo(client);
  868. v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
  869. client->name, state->rev1, state->rev2);
  870. v4l_info(client, "Audio: volume %d%s\n",
  871. state->volume, state->muted ? " (muted)" : "");
  872. if (state->has_sound_processing) {
  873. v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n",
  874. state->balance, state->bass, state->treble,
  875. state->loudness ? "on" : "off");
  876. }
  877. switch (state->mode) {
  878. case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break;
  879. case MSP_MODE_FM_RADIO: p = "FM Radio"; break;
  880. case MSP_MODE_FM_TERRA: p = "Terrestial FM-mono + FM-stereo"; break;
  881. case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break;
  882. case MSP_MODE_FM_NICAM1: p = "NICAM/FM (B/G, D/K)"; break;
  883. case MSP_MODE_FM_NICAM2: p = "NICAM/FM (I)"; break;
  884. case MSP_MODE_AM_NICAM: p = "NICAM/AM (L)"; break;
  885. case MSP_MODE_BTSC: p = "BTSC"; break;
  886. case MSP_MODE_EXTERN: p = "External input"; break;
  887. default: p = "unknown"; break;
  888. }
  889. if (state->opmode == OPMODE_MANUAL) {
  890. v4l_info(client, "Mode: %s (%s%s)\n", p,
  891. (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
  892. (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
  893. } else {
  894. v4l_info(client, "Mode: %s\n", p);
  895. v4l_info(client, "Standard: %s (%s%s)\n",
  896. msp_standard_std_name(state->std),
  897. (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
  898. (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
  899. }
  900. v4l_info(client, "ACB: 0x%04x\n", state->acb);
  901. break;
  902. }
  903. default:
  904. /* unknown */
  905. return -EINVAL;
  906. }
  907. return 0;
  908. }
  909. static int msp_suspend(struct device * dev, pm_message_t state)
  910. {
  911. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  912. v4l_dbg(1, msp_debug, client, "suspend\n");
  913. msp_reset(client);
  914. return 0;
  915. }
  916. static int msp_resume(struct device * dev)
  917. {
  918. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  919. v4l_dbg(1, msp_debug, client, "resume\n");
  920. msp_wake_thread(client);
  921. return 0;
  922. }
  923. /* ----------------------------------------------------------------------- */
  924. static struct i2c_driver i2c_driver;
  925. static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
  926. {
  927. struct i2c_client *client;
  928. struct msp_state *state;
  929. int (*thread_func)(void *data) = NULL;
  930. int msp_hard;
  931. int msp_family;
  932. int msp_revision;
  933. int msp_product, msp_prod_hi, msp_prod_lo;
  934. int msp_rom;
  935. client = kmalloc(sizeof(*client), GFP_KERNEL);
  936. if (client == NULL)
  937. return -ENOMEM;
  938. memset(client, 0, sizeof(*client));
  939. client->addr = address;
  940. client->adapter = adapter;
  941. client->driver = &i2c_driver;
  942. snprintf(client->name, sizeof(client->name) - 1, "msp3400");
  943. if (msp_reset(client) == -1) {
  944. v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
  945. kfree(client);
  946. return -1;
  947. }
  948. state = kmalloc(sizeof(*state), GFP_KERNEL);
  949. if (state == NULL) {
  950. kfree(client);
  951. return -ENOMEM;
  952. }
  953. i2c_set_clientdata(client, state);
  954. memset(state, 0, sizeof(*state));
  955. state->v4l2_std = V4L2_STD_NTSC;
  956. state->volume = 58880; /* 0db gain */
  957. state->balance = 32768; /* 0db gain */
  958. state->bass = 32768;
  959. state->treble = 32768;
  960. state->loudness = 0;
  961. state->input = -1;
  962. state->muted = 0;
  963. state->i2s_mode = 0;
  964. init_waitqueue_head(&state->wq);
  965. state->rev1 = msp_read_dsp(client, 0x1e);
  966. if (state->rev1 != -1)
  967. state->rev2 = msp_read_dsp(client, 0x1f);
  968. v4l_dbg(1, msp_debug, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
  969. if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
  970. v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n");
  971. kfree(state);
  972. kfree(client);
  973. return -1;
  974. }
  975. msp_set_audio(client);
  976. msp_family = ((state->rev1 >> 4) & 0x0f) + 3;
  977. msp_product = (state->rev2 >> 8) & 0xff;
  978. msp_prod_hi = msp_product / 10;
  979. msp_prod_lo = msp_product % 10;
  980. msp_revision = (state->rev1 & 0x0f) + '@';
  981. msp_hard = ((state->rev1 >> 8) & 0xff) + '@';
  982. msp_rom = state->rev2 & 0x1f;
  983. snprintf(client->name, sizeof(client->name), "MSP%d4%02d%c-%c%d",
  984. msp_family, msp_product,
  985. msp_revision, msp_hard, msp_rom);
  986. /* Has NICAM support: all mspx41x and mspx45x products have NICAM */
  987. state->has_nicam = msp_prod_hi == 1 || msp_prod_hi == 5;
  988. /* Has radio support: was added with revision G */
  989. state->has_radio = msp_revision >= 'G';
  990. /* Has headphones output: not for stripped down products */
  991. state->has_headphones = msp_prod_lo < 5;
  992. /* Has scart4 input: not in pre D revisions, not in stripped D revs */
  993. state->has_scart4 = msp_family >= 4 || (msp_revision >= 'D' && msp_prod_lo < 5);
  994. /* Has scart2 and scart3 inputs and scart2 output: not in stripped
  995. down products of the '3' family */
  996. state->has_scart23_in_scart2_out = msp_family >= 4 || msp_prod_lo < 5;
  997. /* Has scart2 a volume control? Not in pre-D revisions. */
  998. state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart23_in_scart2_out;
  999. /* Has a configurable i2s out? */
  1000. state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7;
  1001. /* Has subwoofer output: not in pre-D revs and not in stripped down products */
  1002. state->has_subwoofer = msp_revision >= 'D' && msp_prod_lo < 5;
  1003. /* Has soundprocessing (bass/treble/balance/loudness/equalizer): not in
  1004. stripped down products */
  1005. state->has_sound_processing = msp_prod_lo < 7;
  1006. /* Has Virtual Dolby Surround: only in msp34x1 */
  1007. state->has_virtual_dolby_surround = msp_revision == 'G' && msp_prod_lo == 1;
  1008. /* Has Virtual Dolby Surround & Dolby Pro Logic: only in msp34x2 */
  1009. state->has_dolby_pro_logic = msp_revision == 'G' && msp_prod_lo == 2;
  1010. state->opmode = opmode;
  1011. if (state->opmode == OPMODE_AUTO) {
  1012. /* MSP revision G and up have both autodetect and autoselect */
  1013. if (msp_revision >= 'G')
  1014. state->opmode = OPMODE_AUTOSELECT;
  1015. /* MSP revision D and up have autodetect */
  1016. else if (msp_revision >= 'D')
  1017. state->opmode = OPMODE_AUTODETECT;
  1018. else
  1019. state->opmode = OPMODE_MANUAL;
  1020. }
  1021. /* hello world :-) */
  1022. v4l_info(client, "%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name);
  1023. v4l_info(client, "%s ", client->name);
  1024. if (state->has_nicam && state->has_radio)
  1025. printk("supports nicam and radio, ");
  1026. else if (state->has_nicam)
  1027. printk("supports nicam, ");
  1028. else if (state->has_radio)
  1029. printk("supports radio, ");
  1030. printk("mode is ");
  1031. /* version-specific initialization */
  1032. switch (state->opmode) {
  1033. case OPMODE_MANUAL:
  1034. printk("manual");
  1035. thread_func = msp3400c_thread;
  1036. break;
  1037. case OPMODE_AUTODETECT:
  1038. printk("autodetect");
  1039. thread_func = msp3410d_thread;
  1040. break;
  1041. case OPMODE_AUTOSELECT:
  1042. printk("autodetect and autoselect");
  1043. thread_func = msp34xxg_thread;
  1044. break;
  1045. }
  1046. printk("\n");
  1047. /* startup control thread if needed */
  1048. if (thread_func) {
  1049. state->kthread = kthread_run(thread_func, client, "msp34xx");
  1050. if (state->kthread == NULL)
  1051. v4l_warn(client, "kernel_thread() failed\n");
  1052. msp_wake_thread(client);
  1053. }
  1054. /* done */
  1055. i2c_attach_client(client);
  1056. return 0;
  1057. }
  1058. static int msp_probe(struct i2c_adapter *adapter)
  1059. {
  1060. if (adapter->class & I2C_CLASS_TV_ANALOG)
  1061. return i2c_probe(adapter, &addr_data, msp_attach);
  1062. return 0;
  1063. }
  1064. static int msp_detach(struct i2c_client *client)
  1065. {
  1066. struct msp_state *state = i2c_get_clientdata(client);
  1067. int err;
  1068. /* shutdown control thread */
  1069. if (state->kthread) {
  1070. state->restart = 1;
  1071. kthread_stop(state->kthread);
  1072. }
  1073. msp_reset(client);
  1074. err = i2c_detach_client(client);
  1075. if (err) {
  1076. return err;
  1077. }
  1078. kfree(state);
  1079. kfree(client);
  1080. return 0;
  1081. }
  1082. /* ----------------------------------------------------------------------- */
  1083. /* i2c implementation */
  1084. static struct i2c_driver i2c_driver = {
  1085. .id = I2C_DRIVERID_MSP3400,
  1086. .attach_adapter = msp_probe,
  1087. .detach_client = msp_detach,
  1088. .command = msp_command,
  1089. .driver = {
  1090. .name = "msp3400",
  1091. .suspend = msp_suspend,
  1092. .resume = msp_resume,
  1093. },
  1094. };
  1095. static int __init msp3400_init_module(void)
  1096. {
  1097. return i2c_add_driver(&i2c_driver);
  1098. }
  1099. static void __exit msp3400_cleanup_module(void)
  1100. {
  1101. i2c_del_driver(&i2c_driver);
  1102. }
  1103. module_init(msp3400_init_module);
  1104. module_exit(msp3400_cleanup_module);
  1105. /*
  1106. * Overrides for Emacs so that we follow Linus's tabbing style.
  1107. * ---------------------------------------------------------------------------
  1108. * Local variables:
  1109. * c-basic-offset: 8
  1110. * End:
  1111. */