msp3400.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. /*
  2. * programming the msp34* 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. *
  28. * TODO:
  29. * - better SAT support
  30. *
  31. *
  32. * 980623 Thomas Sailer (sailer@ife.ee.ethz.ch)
  33. * using soundcore instead of OSS
  34. *
  35. */
  36. #include <linux/config.h>
  37. #include <linux/module.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/kernel.h>
  40. #include <linux/sched.h>
  41. #include <linux/string.h>
  42. #include <linux/timer.h>
  43. #include <linux/delay.h>
  44. #include <linux/errno.h>
  45. #include <linux/slab.h>
  46. #include <linux/i2c.h>
  47. #include <linux/videodev.h>
  48. #include <linux/init.h>
  49. #include <linux/smp_lock.h>
  50. #include <linux/kthread.h>
  51. #include <linux/suspend.h>
  52. #include <asm/semaphore.h>
  53. #include <asm/pgtable.h>
  54. #include <media/audiochip.h>
  55. #include "msp3400.h"
  56. #define msp3400_dbg(fmt, arg...) \
  57. do { \
  58. if (debug) \
  59. printk(KERN_INFO "%s debug %d-%04x: " fmt, \
  60. client->driver->driver.name, \
  61. i2c_adapter_id(client->adapter), client->addr , ## arg); \
  62. } while (0)
  63. /* Medium volume debug. */
  64. #define msp3400_dbg_mediumvol(fmt, arg...) \
  65. do { \
  66. if (debug >= 2) \
  67. printk(KERN_INFO "%s debug %d-%04x: " fmt, \
  68. client->driver->driver.name, \
  69. i2c_adapter_id(client->adapter), client->addr , ## arg); \
  70. } while (0)
  71. /* High volume debug. Use with care. */
  72. #define msp3400_dbg_highvol(fmt, arg...) \
  73. do { \
  74. if (debug >= 16) \
  75. printk(KERN_INFO "%s debug %d-%04x: " fmt, \
  76. client->driver->driver.name, \
  77. i2c_adapter_id(client->adapter), client->addr , ## arg); \
  78. } while (0)
  79. #define msp3400_err(fmt, arg...) do { \
  80. printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->driver.name, \
  81. i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
  82. #define msp3400_warn(fmt, arg...) do { \
  83. printk(KERN_WARNING "%s %d-%04x: " fmt, client->driver->driver.name, \
  84. i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
  85. #define msp3400_info(fmt, arg...) do { \
  86. printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->driver.name, \
  87. i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
  88. #define OPMODE_AUTO -1
  89. #define OPMODE_MANUAL 0
  90. #define OPMODE_SIMPLE 1 /* use short programming (>= msp3410 only) */
  91. #define OPMODE_SIMPLER 2 /* use shorter programming (>= msp34xxG) */
  92. /* insmod parameters */
  93. static int opmode = OPMODE_AUTO;
  94. static int debug = 0; /* debug output */
  95. static int once = 0; /* no continous stereo monitoring */
  96. static int amsound = 0; /* hard-wire AM sound at 6.5 Hz (france),
  97. the autoscan seems work well only with FM... */
  98. static int standard = 1; /* Override auto detect of audio standard, if needed. */
  99. static int dolby = 0;
  100. static int stereo_threshold = 0x190; /* a2 threshold for stereo/bilingual
  101. (msp34xxg only) 0x00a0-0x03c0 */
  102. #define DFP_COUNT 0x41
  103. static const int bl_dfp[] = {
  104. 0x00, 0x01, 0x02, 0x03, 0x06, 0x08, 0x09, 0x0a,
  105. 0x0b, 0x0d, 0x0e, 0x10
  106. };
  107. #define IS_MSP34XX_G(msp) ((msp)->opmode==2)
  108. struct msp3400c {
  109. int rev1,rev2;
  110. int opmode;
  111. int nicam;
  112. int mode;
  113. int norm;
  114. int stereo;
  115. int nicam_on;
  116. int acb;
  117. int in_scart;
  118. int i2s_mode;
  119. int main, second; /* sound carrier */
  120. int input;
  121. int source; /* see msp34xxg_set_source */
  122. /* v4l2 */
  123. int audmode;
  124. int rxsubchans;
  125. int muted;
  126. int left, right; /* volume */
  127. int bass, treble;
  128. /* shadow register set */
  129. int dfp_regs[DFP_COUNT];
  130. /* thread */
  131. struct task_struct *kthread;
  132. wait_queue_head_t wq;
  133. int restart:1;
  134. int watch_stereo:1;
  135. };
  136. #define MIN(a,b) (((a)>(b))?(b):(a))
  137. #define MAX(a,b) (((a)>(b))?(a):(b))
  138. #define HAVE_NICAM(msp) (((msp->rev2>>8) & 0xff) != 00)
  139. #define HAVE_SIMPLE(msp) ((msp->rev1 & 0xff) >= 'D'-'@')
  140. #define HAVE_SIMPLER(msp) ((msp->rev1 & 0xff) >= 'G'-'@')
  141. #define HAVE_RADIO(msp) ((msp->rev1 & 0xff) >= 'G'-'@')
  142. #define VIDEO_MODE_RADIO 16 /* norm magic for radio mode */
  143. /* ---------------------------------------------------------------------- */
  144. /* read-only */
  145. module_param(opmode, int, 0444);
  146. /* read-write */
  147. module_param(once, int, 0644);
  148. module_param(debug, int, 0644);
  149. module_param(stereo_threshold, int, 0644);
  150. module_param(standard, int, 0644);
  151. module_param(amsound, int, 0644);
  152. module_param(dolby, int, 0644);
  153. MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Simple, 2=Simpler");
  154. MODULE_PARM_DESC(once, "No continuous stereo monitoring");
  155. MODULE_PARM_DESC(debug, "Enable debug messages");
  156. MODULE_PARM_DESC(stereo_threshold, "Sets signal threshold to activate stereo");
  157. MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
  158. MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
  159. MODULE_PARM_DESC(dolby, "Activates Dolby processsing");
  160. /* ---------------------------------------------------------------------- */
  161. #define I2C_MSP3400C 0x80
  162. #define I2C_MSP3400C_ALT 0x88
  163. #define I2C_MSP3400C_DEM 0x10
  164. #define I2C_MSP3400C_DFP 0x12
  165. /* Addresses to scan */
  166. static unsigned short normal_i2c[] = {
  167. I2C_MSP3400C >> 1,
  168. I2C_MSP3400C_ALT >> 1,
  169. I2C_CLIENT_END
  170. };
  171. I2C_CLIENT_INSMOD;
  172. MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
  173. MODULE_AUTHOR("Gerd Knorr");
  174. MODULE_LICENSE("GPL");
  175. /* ----------------------------------------------------------------------- */
  176. /* functions for talking to the MSP3400C Sound processor */
  177. static int msp3400c_reset(struct i2c_client *client)
  178. {
  179. /* reset and read revision code */
  180. static char reset_off[3] = { 0x00, 0x80, 0x00 };
  181. static char reset_on[3] = { 0x00, 0x00, 0x00 };
  182. static char write[3] = { I2C_MSP3400C_DFP + 1, 0x00, 0x1e };
  183. char read[2];
  184. struct i2c_msg reset[2] = {
  185. { client->addr, I2C_M_IGNORE_NAK, 3, reset_off },
  186. { client->addr, I2C_M_IGNORE_NAK, 3, reset_on },
  187. };
  188. struct i2c_msg test[2] = {
  189. { client->addr, 0, 3, write },
  190. { client->addr, I2C_M_RD, 2, read },
  191. };
  192. msp3400_dbg_highvol("msp3400c_reset\n");
  193. if ( (1 != i2c_transfer(client->adapter,&reset[0],1)) ||
  194. (1 != i2c_transfer(client->adapter,&reset[1],1)) ||
  195. (2 != i2c_transfer(client->adapter,test,2)) ) {
  196. msp3400_err("chip reset failed\n");
  197. return -1;
  198. }
  199. return 0;
  200. }
  201. static int msp3400c_read(struct i2c_client *client, int dev, int addr)
  202. {
  203. int err,retval;
  204. unsigned char write[3];
  205. unsigned char read[2];
  206. struct i2c_msg msgs[2] = {
  207. { client->addr, 0, 3, write },
  208. { client->addr, I2C_M_RD, 2, read }
  209. };
  210. write[0] = dev+1;
  211. write[1] = addr >> 8;
  212. write[2] = addr & 0xff;
  213. for (err = 0; err < 3;) {
  214. if (2 == i2c_transfer(client->adapter,msgs,2))
  215. break;
  216. err++;
  217. msp3400_warn("I/O error #%d (read 0x%02x/0x%02x)\n", err,
  218. dev, addr);
  219. current->state = TASK_INTERRUPTIBLE;
  220. schedule_timeout(msecs_to_jiffies(10));
  221. }
  222. if (3 == err) {
  223. msp3400_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n");
  224. msp3400c_reset(client);
  225. return -1;
  226. }
  227. retval = read[0] << 8 | read[1];
  228. msp3400_dbg_highvol("msp3400c_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
  229. return retval;
  230. }
  231. static int msp3400c_write(struct i2c_client *client, int dev, int addr, int val)
  232. {
  233. int err;
  234. unsigned char buffer[5];
  235. buffer[0] = dev;
  236. buffer[1] = addr >> 8;
  237. buffer[2] = addr & 0xff;
  238. buffer[3] = val >> 8;
  239. buffer[4] = val & 0xff;
  240. msp3400_dbg_highvol("msp3400c_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
  241. for (err = 0; err < 3;) {
  242. if (5 == i2c_master_send(client, buffer, 5))
  243. break;
  244. err++;
  245. msp3400_warn("I/O error #%d (write 0x%02x/0x%02x)\n", err,
  246. dev, addr);
  247. current->state = TASK_INTERRUPTIBLE;
  248. schedule_timeout(msecs_to_jiffies(10));
  249. }
  250. if (3 == err) {
  251. msp3400_warn("giving up, reseting chip. Sound will go off, sorry folks :-|\n");
  252. msp3400c_reset(client);
  253. return -1;
  254. }
  255. return 0;
  256. }
  257. /* ------------------------------------------------------------------------ */
  258. /* This macro is allowed for *constants* only, gcc must calculate it
  259. at compile time. Remember -- no floats in kernel mode */
  260. #define MSP_CARRIER(freq) ((int)((float)(freq/18.432)*(1<<24)))
  261. #define MSP_MODE_AM_DETECT 0
  262. #define MSP_MODE_FM_RADIO 2
  263. #define MSP_MODE_FM_TERRA 3
  264. #define MSP_MODE_FM_SAT 4
  265. #define MSP_MODE_FM_NICAM1 5
  266. #define MSP_MODE_FM_NICAM2 6
  267. #define MSP_MODE_AM_NICAM 7
  268. #define MSP_MODE_BTSC 8
  269. #define MSP_MODE_EXTERN 9
  270. static struct MSP_INIT_DATA_DEM {
  271. int fir1[6];
  272. int fir2[6];
  273. int cdo1;
  274. int cdo2;
  275. int ad_cv;
  276. int mode_reg;
  277. int dfp_src;
  278. int dfp_matrix;
  279. } msp_init_data[] = {
  280. { /* AM (for carrier detect / msp3400) */
  281. {75, 19, 36, 35, 39, 40},
  282. {75, 19, 36, 35, 39, 40},
  283. MSP_CARRIER(5.5), MSP_CARRIER(5.5),
  284. 0x00d0, 0x0500, 0x0020, 0x3000
  285. },{ /* AM (for carrier detect / msp3410) */
  286. {-1, -1, -8, 2, 59, 126},
  287. {-1, -1, -8, 2, 59, 126},
  288. MSP_CARRIER(5.5), MSP_CARRIER(5.5),
  289. 0x00d0, 0x0100, 0x0020, 0x3000
  290. },{ /* FM Radio */
  291. {-8, -8, 4, 6, 78, 107},
  292. {-8, -8, 4, 6, 78, 107},
  293. MSP_CARRIER(10.7), MSP_CARRIER(10.7),
  294. 0x00d0, 0x0480, 0x0020, 0x3000
  295. },{ /* Terrestial FM-mono + FM-stereo */
  296. {3, 18, 27, 48, 66, 72},
  297. {3, 18, 27, 48, 66, 72},
  298. MSP_CARRIER(5.5), MSP_CARRIER(5.5),
  299. 0x00d0, 0x0480, 0x0030, 0x3000
  300. },{ /* Sat FM-mono */
  301. { 1, 9, 14, 24, 33, 37},
  302. { 3, 18, 27, 48, 66, 72},
  303. MSP_CARRIER(6.5), MSP_CARRIER(6.5),
  304. 0x00c6, 0x0480, 0x0000, 0x3000
  305. },{ /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
  306. {-2, -8, -10, 10, 50, 86},
  307. {3, 18, 27, 48, 66, 72},
  308. MSP_CARRIER(5.5), MSP_CARRIER(5.5),
  309. 0x00d0, 0x0040, 0x0120, 0x3000
  310. },{ /* NICAM/FM -- I (6.0/6.552) */
  311. {2, 4, -6, -4, 40, 94},
  312. {3, 18, 27, 48, 66, 72},
  313. MSP_CARRIER(6.0), MSP_CARRIER(6.0),
  314. 0x00d0, 0x0040, 0x0120, 0x3000
  315. },{ /* NICAM/AM -- L (6.5/5.85) */
  316. {-2, -8, -10, 10, 50, 86},
  317. {-4, -12, -9, 23, 79, 126},
  318. MSP_CARRIER(6.5), MSP_CARRIER(6.5),
  319. 0x00c6, 0x0140, 0x0120, 0x7c03
  320. },
  321. };
  322. struct CARRIER_DETECT {
  323. int cdo;
  324. char *name;
  325. };
  326. static struct CARRIER_DETECT carrier_detect_main[] = {
  327. /* main carrier */
  328. { MSP_CARRIER(4.5), "4.5 NTSC" },
  329. { MSP_CARRIER(5.5), "5.5 PAL B/G" },
  330. { MSP_CARRIER(6.0), "6.0 PAL I" },
  331. { MSP_CARRIER(6.5), "6.5 PAL D/K + SAT + SECAM" }
  332. };
  333. static struct CARRIER_DETECT carrier_detect_55[] = {
  334. /* PAL B/G */
  335. { MSP_CARRIER(5.7421875), "5.742 PAL B/G FM-stereo" },
  336. { MSP_CARRIER(5.85), "5.85 PAL B/G NICAM" }
  337. };
  338. static struct CARRIER_DETECT carrier_detect_65[] = {
  339. /* PAL SAT / SECAM */
  340. { MSP_CARRIER(5.85), "5.85 PAL D/K + SECAM NICAM" },
  341. { MSP_CARRIER(6.2578125), "6.25 PAL D/K1 FM-stereo" },
  342. { MSP_CARRIER(6.7421875), "6.74 PAL D/K2 FM-stereo" },
  343. { MSP_CARRIER(7.02), "7.02 PAL SAT FM-stereo s/b" },
  344. { MSP_CARRIER(7.20), "7.20 PAL SAT FM-stereo s" },
  345. { MSP_CARRIER(7.38), "7.38 PAL SAT FM-stereo b" },
  346. };
  347. #define CARRIER_COUNT(x) (sizeof(x)/sizeof(struct CARRIER_DETECT))
  348. /* ----------------------------------------------------------------------- *
  349. * bits 9 8 5 - SCART DSP input Select:
  350. * 0 0 0 - SCART 1 to DSP input (reset position)
  351. * 0 1 0 - MONO to DSP input
  352. * 1 0 0 - SCART 2 to DSP input
  353. * 1 1 1 - Mute DSP input
  354. *
  355. * bits 11 10 6 - SCART 1 Output Select:
  356. * 0 0 0 - undefined (reset position)
  357. * 0 1 0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS)
  358. * 1 0 0 - MONO input to SCART 1 Output
  359. * 1 1 0 - SCART 1 DA to SCART 1 Output
  360. * 0 0 1 - SCART 2 DA to SCART 1 Output
  361. * 0 1 1 - SCART 1 Input to SCART 1 Output
  362. * 1 1 1 - Mute SCART 1 Output
  363. *
  364. * bits 13 12 7 - SCART 2 Output Select (for devices with 2 Output SCART):
  365. * 0 0 0 - SCART 1 DA to SCART 2 Output (reset position)
  366. * 0 1 0 - SCART 1 Input to SCART 2 Output
  367. * 1 0 0 - MONO input to SCART 2 Output
  368. * 0 0 1 - SCART 2 DA to SCART 2 Output
  369. * 0 1 1 - SCART 2 Input to SCART 2 Output
  370. * 1 1 0 - Mute SCART 2 Output
  371. *
  372. * Bits 4 to 0 should be zero.
  373. * ----------------------------------------------------------------------- */
  374. static int scarts[3][9] = {
  375. /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */
  376. /* SCART DSP Input select */
  377. { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 },
  378. /* SCART1 Output select */
  379. { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },
  380. /* SCART2 Output select */
  381. { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },
  382. };
  383. static char *scart_names[] = {
  384. "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"
  385. };
  386. static void msp3400c_set_scart(struct i2c_client *client, int in, int out)
  387. {
  388. struct msp3400c *msp = i2c_get_clientdata(client);
  389. msp->in_scart=in;
  390. if (in >= 1 && in <= 8 && out >= 0 && out <= 2) {
  391. if (-1 == scarts[out][in])
  392. return;
  393. msp->acb &= ~scarts[out][SCART_MASK];
  394. msp->acb |= scarts[out][in];
  395. } else
  396. msp->acb = 0xf60; /* Mute Input and SCART 1 Output */
  397. msp3400_dbg("scart switch: %s => %d (ACB=0x%04x)\n",
  398. scart_names[in], out, msp->acb);
  399. msp3400c_write(client,I2C_MSP3400C_DFP, 0x13, msp->acb);
  400. /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
  401. msp3400c_write(client,I2C_MSP3400C_DEM, 0x40, msp->i2s_mode);
  402. }
  403. /* ------------------------------------------------------------------------ */
  404. static void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2)
  405. {
  406. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0093, cdo1 & 0xfff);
  407. msp3400c_write(client,I2C_MSP3400C_DEM, 0x009b, cdo1 >> 12);
  408. msp3400c_write(client,I2C_MSP3400C_DEM, 0x00a3, cdo2 & 0xfff);
  409. msp3400c_write(client,I2C_MSP3400C_DEM, 0x00ab, cdo2 >> 12);
  410. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
  411. }
  412. static void msp3400c_setvolume(struct i2c_client *client,
  413. int muted, int left, int right)
  414. {
  415. int vol = 0, val = 0, balance = 0;
  416. if (!muted) {
  417. /* 0x7f instead if 0x73 here has sound quality issues,
  418. * probably due to overmodulation + clipping ... */
  419. vol = (left > right) ? left : right;
  420. val = (vol * 0x73 / 65535) << 8;
  421. }
  422. if (vol > 0) {
  423. balance = ((right - left) * 127) / vol;
  424. }
  425. msp3400_dbg("setvolume: mute=%s %d:%d v=0x%02x b=0x%02x\n",
  426. muted ? "on" : "off", left, right, val >> 8, balance);
  427. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0000, val); /* loudspeaker */
  428. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0006, val); /* headphones */
  429. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0007,
  430. muted ? 0x1 : (val | 0x1));
  431. msp3400c_write(client, I2C_MSP3400C_DFP, 0x0001, balance << 8);
  432. }
  433. static void msp3400c_setbass(struct i2c_client *client, int bass)
  434. {
  435. int val = ((bass-32768) * 0x60 / 65535) << 8;
  436. msp3400_dbg("setbass: %d 0x%02x\n", bass, val >> 8);
  437. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0002, val); /* loudspeaker */
  438. }
  439. static void msp3400c_settreble(struct i2c_client *client, int treble)
  440. {
  441. int val = ((treble-32768) * 0x60 / 65535) << 8;
  442. msp3400_dbg("settreble: %d 0x%02x\n",treble, val>>8);
  443. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0003, val); /* loudspeaker */
  444. }
  445. static void msp3400c_setmode(struct i2c_client *client, int type)
  446. {
  447. struct msp3400c *msp = i2c_get_clientdata(client);
  448. int i;
  449. msp3400_dbg("setmode: %d\n",type);
  450. msp->mode = type;
  451. msp->audmode = V4L2_TUNER_MODE_MONO;
  452. msp->rxsubchans = V4L2_TUNER_SUB_MONO;
  453. msp3400c_write(client,I2C_MSP3400C_DEM, 0x00bb, /* ad_cv */
  454. msp_init_data[type].ad_cv);
  455. for (i = 5; i >= 0; i--) /* fir 1 */
  456. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0001,
  457. msp_init_data[type].fir1[i]);
  458. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0004); /* fir 2 */
  459. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0040);
  460. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0000);
  461. for (i = 5; i >= 0; i--)
  462. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005,
  463. msp_init_data[type].fir2[i]);
  464. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0083, /* MODE_REG */
  465. msp_init_data[type].mode_reg);
  466. msp3400c_setcarrier(client, msp_init_data[type].cdo1,
  467. msp_init_data[type].cdo2);
  468. msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/
  469. if (dolby) {
  470. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
  471. 0x0520); /* I2S1 */
  472. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
  473. 0x0620); /* I2S2 */
  474. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
  475. msp_init_data[type].dfp_src);
  476. } else {
  477. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,
  478. msp_init_data[type].dfp_src);
  479. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,
  480. msp_init_data[type].dfp_src);
  481. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,
  482. msp_init_data[type].dfp_src);
  483. }
  484. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,
  485. msp_init_data[type].dfp_src);
  486. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e,
  487. msp_init_data[type].dfp_matrix);
  488. if (HAVE_NICAM(msp)) {
  489. /* nicam prescale */
  490. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0010, 0x5a00); /* was: 0x3000 */
  491. }
  492. }
  493. /* given a bitmask of VIDEO_SOUND_XXX returns the "best" in the bitmask */
  494. static int best_video_sound(int rxsubchans)
  495. {
  496. if (rxsubchans & V4L2_TUNER_SUB_STEREO)
  497. return V4L2_TUNER_MODE_STEREO;
  498. if (rxsubchans & V4L2_TUNER_SUB_LANG1)
  499. return V4L2_TUNER_MODE_LANG1;
  500. if (rxsubchans & V4L2_TUNER_SUB_LANG2)
  501. return V4L2_TUNER_MODE_LANG2;
  502. return V4L2_TUNER_MODE_MONO;
  503. }
  504. /* turn on/off nicam + stereo */
  505. static void msp3400c_setstereo(struct i2c_client *client, int mode)
  506. {
  507. static char *strmode[] = { "0", "mono", "stereo", "3",
  508. "lang1", "5", "6", "7", "lang2"
  509. };
  510. struct msp3400c *msp = i2c_get_clientdata(client);
  511. int nicam = 0; /* channel source: FM/AM or nicam */
  512. int src = 0;
  513. if (IS_MSP34XX_G(msp)) {
  514. /* this method would break everything, let's make sure
  515. * it's never called
  516. */
  517. msp3400_dbg
  518. ("DEBUG WARNING setstereo called with mode=%d instead of set_source (ignored)\n",
  519. mode);
  520. return;
  521. }
  522. /* switch demodulator */
  523. switch (msp->mode) {
  524. case MSP_MODE_FM_TERRA:
  525. msp3400_dbg("FM setstereo: %s\n", strmode[mode]);
  526. msp3400c_setcarrier(client,msp->second,msp->main);
  527. switch (mode) {
  528. case V4L2_TUNER_MODE_STEREO:
  529. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3001);
  530. break;
  531. case V4L2_TUNER_MODE_MONO:
  532. case V4L2_TUNER_MODE_LANG1:
  533. case V4L2_TUNER_MODE_LANG2:
  534. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e, 0x3000);
  535. break;
  536. }
  537. break;
  538. case MSP_MODE_FM_SAT:
  539. msp3400_dbg("SAT setstereo: %s\n", strmode[mode]);
  540. switch (mode) {
  541. case V4L2_TUNER_MODE_MONO:
  542. msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
  543. break;
  544. case V4L2_TUNER_MODE_STEREO:
  545. msp3400c_setcarrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
  546. break;
  547. case V4L2_TUNER_MODE_LANG1:
  548. msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
  549. break;
  550. case V4L2_TUNER_MODE_LANG2:
  551. msp3400c_setcarrier(client, MSP_CARRIER(7.38), MSP_CARRIER(7.02));
  552. break;
  553. }
  554. break;
  555. case MSP_MODE_FM_NICAM1:
  556. case MSP_MODE_FM_NICAM2:
  557. case MSP_MODE_AM_NICAM:
  558. msp3400_dbg("NICAM setstereo: %s\n",strmode[mode]);
  559. msp3400c_setcarrier(client,msp->second,msp->main);
  560. if (msp->nicam_on)
  561. nicam=0x0100;
  562. break;
  563. case MSP_MODE_BTSC:
  564. msp3400_dbg("BTSC setstereo: %s\n",strmode[mode]);
  565. nicam=0x0300;
  566. break;
  567. case MSP_MODE_EXTERN:
  568. msp3400_dbg("extern setstereo: %s\n",strmode[mode]);
  569. nicam = 0x0200;
  570. break;
  571. case MSP_MODE_FM_RADIO:
  572. msp3400_dbg("FM-Radio setstereo: %s\n",strmode[mode]);
  573. break;
  574. default:
  575. msp3400_dbg("mono setstereo\n");
  576. return;
  577. }
  578. /* switch audio */
  579. switch (best_video_sound(mode)) {
  580. case V4L2_TUNER_MODE_STEREO:
  581. src = 0x0020 | nicam;
  582. break;
  583. case V4L2_TUNER_MODE_MONO:
  584. if (msp->mode == MSP_MODE_AM_NICAM) {
  585. msp3400_dbg("switching to AM mono\n");
  586. /* AM mono decoding is handled by tuner, not MSP chip */
  587. /* SCART switching control register */
  588. msp3400c_set_scart(client,SCART_MONO,0);
  589. src = 0x0200;
  590. break;
  591. }
  592. case V4L2_TUNER_MODE_LANG1:
  593. src = 0x0000 | nicam;
  594. break;
  595. case V4L2_TUNER_MODE_LANG2:
  596. src = 0x0010 | nicam;
  597. break;
  598. }
  599. msp3400_dbg("setstereo final source/matrix = 0x%x\n", src);
  600. if (dolby) {
  601. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,0x0520);
  602. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,0x0620);
  603. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
  604. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
  605. } else {
  606. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,src);
  607. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,src);
  608. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,src);
  609. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,src);
  610. }
  611. }
  612. static void
  613. msp3400c_print_mode(struct i2c_client *client)
  614. {
  615. struct msp3400c *msp = i2c_get_clientdata(client);
  616. if (msp->main == msp->second) {
  617. msp3400_dbg("mono sound carrier: %d.%03d MHz\n",
  618. msp->main/910000,(msp->main/910)%1000);
  619. } else {
  620. msp3400_dbg("main sound carrier: %d.%03d MHz\n",
  621. msp->main/910000,(msp->main/910)%1000);
  622. }
  623. if (msp->mode == MSP_MODE_FM_NICAM1 || msp->mode == MSP_MODE_FM_NICAM2)
  624. msp3400_dbg("NICAM/FM carrier : %d.%03d MHz\n",
  625. msp->second/910000,(msp->second/910)%1000);
  626. if (msp->mode == MSP_MODE_AM_NICAM)
  627. msp3400_dbg("NICAM/AM carrier : %d.%03d MHz\n",
  628. msp->second/910000,(msp->second/910)%1000);
  629. if (msp->mode == MSP_MODE_FM_TERRA &&
  630. msp->main != msp->second) {
  631. msp3400_dbg("FM-stereo carrier : %d.%03d MHz\n",
  632. msp->second/910000,(msp->second/910)%1000);
  633. }
  634. }
  635. #define MSP3400_MAX 4
  636. static struct i2c_client *msps[MSP3400_MAX];
  637. static void msp3400c_restore_dfp(struct i2c_client *client)
  638. {
  639. struct msp3400c *msp = i2c_get_clientdata(client);
  640. int i;
  641. for (i = 0; i < DFP_COUNT; i++) {
  642. if (-1 == msp->dfp_regs[i])
  643. continue;
  644. msp3400c_write(client, I2C_MSP3400C_DFP, i, msp->dfp_regs[i]);
  645. }
  646. }
  647. /* if the dfp_regs is set, set what's in there. Otherwise, set the default value */
  648. static int msp3400c_write_dfp_with_default(struct i2c_client *client,
  649. int addr, int default_value)
  650. {
  651. struct msp3400c *msp = i2c_get_clientdata(client);
  652. int value = default_value;
  653. if (addr < DFP_COUNT && -1 != msp->dfp_regs[addr])
  654. value = msp->dfp_regs[addr];
  655. return msp3400c_write(client, I2C_MSP3400C_DFP, addr, value);
  656. }
  657. /* ----------------------------------------------------------------------- */
  658. struct REGISTER_DUMP {
  659. int addr;
  660. char *name;
  661. };
  662. struct REGISTER_DUMP d1[] = {
  663. {0x007e, "autodetect"},
  664. {0x0023, "C_AD_BITS "},
  665. {0x0038, "ADD_BITS "},
  666. {0x003e, "CIB_BITS "},
  667. {0x0057, "ERROR_RATE"},
  668. };
  669. static int autodetect_stereo(struct i2c_client *client)
  670. {
  671. struct msp3400c *msp = i2c_get_clientdata(client);
  672. int val;
  673. int rxsubchans = msp->rxsubchans;
  674. int newnicam = msp->nicam_on;
  675. int update = 0;
  676. switch (msp->mode) {
  677. case MSP_MODE_FM_TERRA:
  678. val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x18);
  679. if (val > 32767)
  680. val -= 65536;
  681. msp3400_dbg("stereo detect register: %d\n",val);
  682. if (val > 4096) {
  683. rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
  684. } else if (val < -4096) {
  685. rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  686. } else {
  687. rxsubchans = V4L2_TUNER_SUB_MONO;
  688. }
  689. newnicam = 0;
  690. break;
  691. case MSP_MODE_FM_NICAM1:
  692. case MSP_MODE_FM_NICAM2:
  693. case MSP_MODE_AM_NICAM:
  694. val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x23);
  695. msp3400_dbg("nicam sync=%d, mode=%d\n",
  696. val & 1, (val & 0x1e) >> 1);
  697. if (val & 1) {
  698. /* nicam synced */
  699. switch ((val & 0x1e) >> 1) {
  700. case 0:
  701. case 8:
  702. rxsubchans = V4L2_TUNER_SUB_STEREO;
  703. break;
  704. case 1:
  705. case 9:
  706. rxsubchans = V4L2_TUNER_SUB_MONO
  707. | V4L2_TUNER_SUB_LANG1;
  708. break;
  709. case 2:
  710. case 10:
  711. rxsubchans = V4L2_TUNER_SUB_MONO
  712. | V4L2_TUNER_SUB_LANG1
  713. | V4L2_TUNER_SUB_LANG2;
  714. break;
  715. default:
  716. rxsubchans = V4L2_TUNER_SUB_MONO;
  717. break;
  718. }
  719. newnicam=1;
  720. } else {
  721. newnicam = 0;
  722. rxsubchans = V4L2_TUNER_SUB_MONO;
  723. }
  724. break;
  725. case MSP_MODE_BTSC:
  726. val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x200);
  727. msp3400_dbg("status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
  728. val,
  729. (val & 0x0002) ? "no" : "yes",
  730. (val & 0x0004) ? "no" : "yes",
  731. (val & 0x0040) ? "stereo" : "mono",
  732. (val & 0x0080) ? ", nicam 2nd mono" : "",
  733. (val & 0x0100) ? ", bilingual/SAP" : "");
  734. rxsubchans = V4L2_TUNER_SUB_MONO;
  735. if (val & 0x0040) rxsubchans |= V4L2_TUNER_SUB_STEREO;
  736. if (val & 0x0100) rxsubchans |= V4L2_TUNER_SUB_LANG1;
  737. break;
  738. }
  739. if (rxsubchans != msp->rxsubchans) {
  740. update = 1;
  741. msp3400_dbg("watch: rxsubchans %d => %d\n",
  742. msp->rxsubchans,rxsubchans);
  743. msp->rxsubchans = rxsubchans;
  744. }
  745. if (newnicam != msp->nicam_on) {
  746. update = 1;
  747. msp3400_dbg("watch: nicam %d => %d\n",
  748. msp->nicam_on,newnicam);
  749. msp->nicam_on = newnicam;
  750. }
  751. return update;
  752. }
  753. /*
  754. * A kernel thread for msp3400 control -- we don't want to block the
  755. * in the ioctl while doing the sound carrier & stereo detect
  756. */
  757. static int msp34xx_sleep(struct msp3400c *msp, int timeout)
  758. {
  759. DECLARE_WAITQUEUE(wait, current);
  760. add_wait_queue(&msp->wq, &wait);
  761. if (!kthread_should_stop()) {
  762. if (timeout < 0) {
  763. set_current_state(TASK_INTERRUPTIBLE);
  764. schedule();
  765. } else {
  766. schedule_timeout_interruptible
  767. (msecs_to_jiffies(timeout));
  768. }
  769. }
  770. remove_wait_queue(&msp->wq, &wait);
  771. try_to_freeze();
  772. return msp->restart;
  773. }
  774. /* stereo/multilang monitoring */
  775. static void watch_stereo(struct i2c_client *client)
  776. {
  777. struct msp3400c *msp = i2c_get_clientdata(client);
  778. if (autodetect_stereo(client)) {
  779. if (msp->stereo & V4L2_TUNER_MODE_STEREO)
  780. msp3400c_setstereo(client, V4L2_TUNER_MODE_STEREO);
  781. else if (msp->stereo & VIDEO_SOUND_LANG1)
  782. msp3400c_setstereo(client, V4L2_TUNER_MODE_LANG1);
  783. else
  784. msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
  785. }
  786. if (once)
  787. msp->watch_stereo = 0;
  788. }
  789. static int msp3400c_thread(void *data)
  790. {
  791. struct i2c_client *client = data;
  792. struct msp3400c *msp = i2c_get_clientdata(client);
  793. struct CARRIER_DETECT *cd;
  794. int count, max1,max2,val1,val2, val,this;
  795. msp3400_info("msp3400 daemon started\n");
  796. for (;;) {
  797. msp3400_dbg_mediumvol("msp3400 thread: sleep\n");
  798. msp34xx_sleep(msp,-1);
  799. msp3400_dbg_mediumvol("msp3400 thread: wakeup\n");
  800. restart:
  801. msp3400_dbg("thread: restart scan\n");
  802. msp->restart = 0;
  803. if (kthread_should_stop())
  804. break;
  805. if (VIDEO_MODE_RADIO == msp->norm ||
  806. MSP_MODE_EXTERN == msp->mode) {
  807. /* no carrier scan, just unmute */
  808. msp3400_info("thread: no carrier scan\n");
  809. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  810. continue;
  811. }
  812. /* mute */
  813. msp3400c_setvolume(client, msp->muted, 0, 0);
  814. msp3400c_setmode(client, MSP_MODE_AM_DETECT /* +1 */ );
  815. val1 = val2 = 0;
  816. max1 = max2 = -1;
  817. msp->watch_stereo = 0;
  818. /* some time for the tuner to sync */
  819. if (msp34xx_sleep(msp,200))
  820. goto restart;
  821. /* carrier detect pass #1 -- main carrier */
  822. cd = carrier_detect_main;
  823. count = CARRIER_COUNT(carrier_detect_main);
  824. if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {
  825. /* autodetect doesn't work well with AM ... */
  826. max1 = 3;
  827. count = 0;
  828. msp3400_dbg("AM sound override\n");
  829. }
  830. for (this = 0; this < count; this++) {
  831. msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
  832. if (msp34xx_sleep(msp,100))
  833. goto restart;
  834. val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
  835. if (val > 32767)
  836. val -= 65536;
  837. if (val1 < val)
  838. val1 = val, max1 = this;
  839. msp3400_dbg("carrier1 val: %5d / %s\n", val,cd[this].name);
  840. }
  841. /* carrier detect pass #2 -- second (stereo) carrier */
  842. switch (max1) {
  843. case 1: /* 5.5 */
  844. cd = carrier_detect_55;
  845. count = CARRIER_COUNT(carrier_detect_55);
  846. break;
  847. case 3: /* 6.5 */
  848. cd = carrier_detect_65;
  849. count = CARRIER_COUNT(carrier_detect_65);
  850. break;
  851. case 0: /* 4.5 */
  852. case 2: /* 6.0 */
  853. default:
  854. cd = NULL;
  855. count = 0;
  856. break;
  857. }
  858. if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {
  859. /* autodetect doesn't work well with AM ... */
  860. cd = NULL;
  861. count = 0;
  862. max2 = 0;
  863. }
  864. for (this = 0; this < count; this++) {
  865. msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);
  866. if (msp34xx_sleep(msp,100))
  867. goto restart;
  868. val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);
  869. if (val > 32767)
  870. val -= 65536;
  871. if (val2 < val)
  872. val2 = val, max2 = this;
  873. msp3400_dbg("carrier2 val: %5d / %s\n", val,cd[this].name);
  874. }
  875. /* programm the msp3400 according to the results */
  876. msp->main = carrier_detect_main[max1].cdo;
  877. switch (max1) {
  878. case 1: /* 5.5 */
  879. if (max2 == 0) {
  880. /* B/G FM-stereo */
  881. msp->second = carrier_detect_55[max2].cdo;
  882. msp3400c_setmode(client, MSP_MODE_FM_TERRA);
  883. msp->nicam_on = 0;
  884. msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
  885. msp->watch_stereo = 1;
  886. } else if (max2 == 1 && HAVE_NICAM(msp)) {
  887. /* B/G NICAM */
  888. msp->second = carrier_detect_55[max2].cdo;
  889. msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
  890. msp->nicam_on = 1;
  891. msp3400c_setcarrier(client, msp->second, msp->main);
  892. msp->watch_stereo = 1;
  893. } else {
  894. goto no_second;
  895. }
  896. break;
  897. case 2: /* 6.0 */
  898. /* PAL I NICAM */
  899. msp->second = MSP_CARRIER(6.552);
  900. msp3400c_setmode(client, MSP_MODE_FM_NICAM2);
  901. msp->nicam_on = 1;
  902. msp3400c_setcarrier(client, msp->second, msp->main);
  903. msp->watch_stereo = 1;
  904. break;
  905. case 3: /* 6.5 */
  906. if (max2 == 1 || max2 == 2) {
  907. /* D/K FM-stereo */
  908. msp->second = carrier_detect_65[max2].cdo;
  909. msp3400c_setmode(client, MSP_MODE_FM_TERRA);
  910. msp->nicam_on = 0;
  911. msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
  912. msp->watch_stereo = 1;
  913. } else if (max2 == 0 &&
  914. msp->norm == VIDEO_MODE_SECAM) {
  915. /* L NICAM or AM-mono */
  916. msp->second = carrier_detect_65[max2].cdo;
  917. msp3400c_setmode(client, MSP_MODE_AM_NICAM);
  918. msp->nicam_on = 0;
  919. msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
  920. msp3400c_setcarrier(client, msp->second, msp->main);
  921. /* volume prescale for SCART (AM mono input) */
  922. msp3400c_write(client,I2C_MSP3400C_DFP, 0x000d, 0x1900);
  923. msp->watch_stereo = 1;
  924. } else if (max2 == 0 && HAVE_NICAM(msp)) {
  925. /* D/K NICAM */
  926. msp->second = carrier_detect_65[max2].cdo;
  927. msp3400c_setmode(client, MSP_MODE_FM_NICAM1);
  928. msp->nicam_on = 1;
  929. msp3400c_setcarrier(client, msp->second, msp->main);
  930. msp->watch_stereo = 1;
  931. } else {
  932. goto no_second;
  933. }
  934. break;
  935. case 0: /* 4.5 */
  936. default:
  937. no_second:
  938. msp->second = carrier_detect_main[max1].cdo;
  939. msp3400c_setmode(client, MSP_MODE_FM_TERRA);
  940. msp->nicam_on = 0;
  941. msp3400c_setcarrier(client, msp->second, msp->main);
  942. msp->rxsubchans = V4L2_TUNER_SUB_MONO;
  943. msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
  944. break;
  945. }
  946. /* unmute */
  947. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  948. msp3400c_restore_dfp(client);
  949. if (debug)
  950. msp3400c_print_mode(client);
  951. /* monitor tv audio mode */
  952. while (msp->watch_stereo) {
  953. if (msp34xx_sleep(msp,5000))
  954. goto restart;
  955. watch_stereo(client);
  956. }
  957. }
  958. msp3400_dbg("thread: exit\n");
  959. return 0;
  960. }
  961. /* ----------------------------------------------------------------------- */
  962. /* this one uses the automatic sound standard detection of newer */
  963. /* msp34xx chip versions */
  964. static struct MODES {
  965. int retval;
  966. int main, second;
  967. char *name;
  968. } modelist[] = {
  969. { 0x0000, 0, 0, "ERROR" },
  970. { 0x0001, 0, 0, "autodetect start" },
  971. { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72 M Dual FM-Stereo" },
  972. { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74 B/G Dual FM-Stereo" },
  973. { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
  974. { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
  975. { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
  976. { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
  977. { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
  978. { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
  979. { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
  980. { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
  981. { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
  982. { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
  983. { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
  984. { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7 FM-Stereo Radio" },
  985. { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 SAT-Mono" },
  986. { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20 SAT-Stereo" },
  987. { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2 SAT ADR" },
  988. { -1, 0, 0, NULL }, /* EOF */
  989. };
  990. static inline const char *msp34xx_standard_mode_name(int mode)
  991. {
  992. int i;
  993. for (i = 0; modelist[i].name != NULL; i++)
  994. if (modelist[i].retval == mode)
  995. return modelist[i].name;
  996. return "unknown";
  997. }
  998. static int msp34xx_modus(struct i2c_client *client, int norm)
  999. {
  1000. switch (norm) {
  1001. case VIDEO_MODE_PAL:
  1002. msp3400_dbg("video mode selected to PAL\n");
  1003. #if 1
  1004. /* experimental: not sure this works with all chip versions */
  1005. return 0x7003;
  1006. #else
  1007. /* previous value, try this if it breaks ... */
  1008. return 0x1003;
  1009. #endif
  1010. case VIDEO_MODE_NTSC: /* BTSC */
  1011. msp3400_dbg("video mode selected to NTSC\n");
  1012. return 0x2003;
  1013. case VIDEO_MODE_SECAM:
  1014. msp3400_dbg("video mode selected to SECAM\n");
  1015. return 0x0003;
  1016. case VIDEO_MODE_RADIO:
  1017. msp3400_dbg("video mode selected to Radio\n");
  1018. return 0x0003;
  1019. case VIDEO_MODE_AUTO:
  1020. msp3400_dbg("video mode selected to Auto\n");
  1021. return 0x2003;
  1022. default:
  1023. return 0x0003;
  1024. }
  1025. }
  1026. static int msp34xx_standard(int norm)
  1027. {
  1028. switch (norm) {
  1029. case VIDEO_MODE_PAL:
  1030. return 1;
  1031. case VIDEO_MODE_NTSC: /* BTSC */
  1032. return 0x0020;
  1033. case VIDEO_MODE_SECAM:
  1034. return 1;
  1035. case VIDEO_MODE_RADIO:
  1036. return 0x0040;
  1037. default:
  1038. return 1;
  1039. }
  1040. }
  1041. static int msp3410d_thread(void *data)
  1042. {
  1043. struct i2c_client *client = data;
  1044. struct msp3400c *msp = i2c_get_clientdata(client);
  1045. int mode,val,i,std;
  1046. msp3400_info("msp3410 daemon started\n");
  1047. for (;;) {
  1048. msp3400_dbg_mediumvol("msp3410 thread: sleep\n");
  1049. msp34xx_sleep(msp,-1);
  1050. msp3400_dbg_mediumvol("msp3410 thread: wakeup\n");
  1051. restart:
  1052. msp3400_dbg("thread: restart scan\n");
  1053. msp->restart = 0;
  1054. if (kthread_should_stop())
  1055. break;
  1056. if (msp->mode == MSP_MODE_EXTERN) {
  1057. /* no carrier scan needed, just unmute */
  1058. msp3400_dbg("thread: no carrier scan\n");
  1059. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1060. continue;
  1061. }
  1062. /* put into sane state (and mute) */
  1063. msp3400c_reset(client);
  1064. /* some time for the tuner to sync */
  1065. if (msp34xx_sleep(msp,200))
  1066. goto restart;
  1067. /* start autodetect */
  1068. mode = msp34xx_modus(client, msp->norm);
  1069. std = msp34xx_standard(msp->norm);
  1070. msp3400c_write(client, I2C_MSP3400C_DEM, 0x30, mode);
  1071. msp3400c_write(client, I2C_MSP3400C_DEM, 0x20, std);
  1072. msp->watch_stereo = 0;
  1073. if (debug)
  1074. msp3400_dbg("setting mode: %s (0x%04x)\n",
  1075. msp34xx_standard_mode_name(std) ,std);
  1076. if (std != 1) {
  1077. /* programmed some specific mode */
  1078. val = std;
  1079. } else {
  1080. /* triggered autodetect */
  1081. for (;;) {
  1082. if (msp34xx_sleep(msp,100))
  1083. goto restart;
  1084. /* check results */
  1085. val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x7e);
  1086. if (val < 0x07ff)
  1087. break;
  1088. msp3400_dbg("detection still in progress\n");
  1089. }
  1090. }
  1091. for (i = 0; modelist[i].name != NULL; i++)
  1092. if (modelist[i].retval == val)
  1093. break;
  1094. msp3400_dbg("current mode: %s (0x%04x)\n",
  1095. modelist[i].name ? modelist[i].name : "unknown",
  1096. val);
  1097. msp->main = modelist[i].main;
  1098. msp->second = modelist[i].second;
  1099. if (amsound && (msp->norm == VIDEO_MODE_SECAM) && (val != 0x0009)) {
  1100. /* autodetection has failed, let backup */
  1101. msp3400_dbg("autodetection failed,"
  1102. " switching to backup mode: %s (0x%04x)\n",
  1103. modelist[8].name ? modelist[8].name : "unknown",val);
  1104. val = 0x0009;
  1105. msp3400c_write(client, I2C_MSP3400C_DEM, 0x20, val);
  1106. }
  1107. /* set various prescales */
  1108. msp3400c_write(client, I2C_MSP3400C_DFP, 0x0d, 0x1900); /* scart */
  1109. msp3400c_write(client, I2C_MSP3400C_DFP, 0x0e, 0x2403); /* FM */
  1110. msp3400c_write(client, I2C_MSP3400C_DFP, 0x10, 0x5a00); /* nicam */
  1111. /* set stereo */
  1112. switch (val) {
  1113. case 0x0008: /* B/G NICAM */
  1114. case 0x000a: /* I NICAM */
  1115. if (val == 0x0008)
  1116. msp->mode = MSP_MODE_FM_NICAM1;
  1117. else
  1118. msp->mode = MSP_MODE_FM_NICAM2;
  1119. /* just turn on stereo */
  1120. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1121. msp->nicam_on = 1;
  1122. msp->watch_stereo = 1;
  1123. msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
  1124. break;
  1125. case 0x0009:
  1126. msp->mode = MSP_MODE_AM_NICAM;
  1127. msp->rxsubchans = V4L2_TUNER_SUB_MONO;
  1128. msp->nicam_on = 1;
  1129. msp3400c_setstereo(client,V4L2_TUNER_MODE_MONO);
  1130. msp->watch_stereo = 1;
  1131. break;
  1132. case 0x0020: /* BTSC */
  1133. /* just turn on stereo */
  1134. msp->mode = MSP_MODE_BTSC;
  1135. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1136. msp->nicam_on = 0;
  1137. msp->watch_stereo = 1;
  1138. msp3400c_setstereo(client,V4L2_TUNER_MODE_STEREO);
  1139. break;
  1140. case 0x0040: /* FM radio */
  1141. msp->mode = MSP_MODE_FM_RADIO;
  1142. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1143. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1144. msp->nicam_on = 0;
  1145. msp->watch_stereo = 0;
  1146. /* not needed in theory if HAVE_RADIO(), but
  1147. short programming enables carrier mute */
  1148. msp3400c_setmode(client,MSP_MODE_FM_RADIO);
  1149. msp3400c_setcarrier(client, MSP_CARRIER(10.7),
  1150. MSP_CARRIER(10.7));
  1151. /* scart routing */
  1152. msp3400c_set_scart(client,SCART_IN2,0);
  1153. /* msp34xx does radio decoding */
  1154. msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020);
  1155. msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020);
  1156. msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020);
  1157. break;
  1158. case 0x0003:
  1159. case 0x0004:
  1160. case 0x0005:
  1161. msp->mode = MSP_MODE_FM_TERRA;
  1162. msp->rxsubchans = V4L2_TUNER_SUB_MONO;
  1163. msp->audmode = V4L2_TUNER_MODE_MONO;
  1164. msp->nicam_on = 0;
  1165. msp->watch_stereo = 1;
  1166. break;
  1167. }
  1168. /* unmute, restore misc registers */
  1169. msp3400c_setbass(client, msp->bass);
  1170. msp3400c_settreble(client, msp->treble);
  1171. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1172. msp3400c_write(client, I2C_MSP3400C_DFP, 0x13, msp->acb);
  1173. msp3400c_write(client,I2C_MSP3400C_DEM, 0x40, msp->i2s_mode);
  1174. msp3400c_restore_dfp(client);
  1175. /* monitor tv audio mode */
  1176. while (msp->watch_stereo) {
  1177. if (msp34xx_sleep(msp,5000))
  1178. goto restart;
  1179. watch_stereo(client);
  1180. }
  1181. }
  1182. msp3400_dbg("thread: exit\n");
  1183. return 0;
  1184. }
  1185. /* ----------------------------------------------------------------------- */
  1186. /* msp34xxG + (simpler no-thread) */
  1187. /* this one uses both automatic standard detection and automatic sound */
  1188. /* select which are available in the newer G versions */
  1189. /* struct msp: only norm, acb and source are really used in this mode */
  1190. static void msp34xxg_set_source(struct i2c_client *client, int source);
  1191. /* (re-)initialize the msp34xxg, according to the current norm in msp->norm
  1192. * return 0 if it worked, -1 if it failed
  1193. */
  1194. static int msp34xxg_reset(struct i2c_client *client)
  1195. {
  1196. struct msp3400c *msp = i2c_get_clientdata(client);
  1197. int modus,std;
  1198. if (msp3400c_reset(client))
  1199. return -1;
  1200. /* make sure that input/output is muted (paranoid mode) */
  1201. if (msp3400c_write(client,
  1202. I2C_MSP3400C_DFP,
  1203. 0x13, /* ACB */
  1204. 0x0f20 /* mute DSP input, mute SCART 1 */))
  1205. return -1;
  1206. msp3400c_write(client,I2C_MSP3400C_DEM, 0x40, msp->i2s_mode);
  1207. /* step-by-step initialisation, as described in the manual */
  1208. modus = msp34xx_modus(client, msp->norm);
  1209. std = msp34xx_standard(msp->norm);
  1210. modus &= ~0x03; /* STATUS_CHANGE=0 */
  1211. modus |= 0x01; /* AUTOMATIC_SOUND_DETECTION=1 */
  1212. if (msp3400c_write(client,
  1213. I2C_MSP3400C_DEM,
  1214. 0x30/*MODUS*/,
  1215. modus))
  1216. return -1;
  1217. if (msp3400c_write(client,
  1218. I2C_MSP3400C_DEM,
  1219. 0x20/*standard*/,
  1220. std))
  1221. return -1;
  1222. /* write the dfps that may have an influence on
  1223. standard/audio autodetection right now */
  1224. msp34xxg_set_source(client, msp->source);
  1225. if (msp3400c_write_dfp_with_default(client, 0x0e, /* AM/FM Prescale */
  1226. 0x3000
  1227. /* default: [15:8] 75khz deviation */
  1228. ))
  1229. return -1;
  1230. if (msp3400c_write_dfp_with_default(client, 0x10, /* NICAM Prescale */
  1231. 0x5a00
  1232. /* default: 9db gain (as recommended) */
  1233. ))
  1234. return -1;
  1235. return 0;
  1236. }
  1237. static int msp34xxg_thread(void *data)
  1238. {
  1239. struct i2c_client *client = data;
  1240. struct msp3400c *msp = i2c_get_clientdata(client);
  1241. int val, std, i;
  1242. msp3400_info("msp34xxg daemon started\n");
  1243. msp->source = 1; /* default */
  1244. for (;;) {
  1245. msp3400_dbg_mediumvol("msp34xxg thread: sleep\n");
  1246. msp34xx_sleep(msp,-1);
  1247. msp3400_dbg_mediumvol("msp34xxg thread: wakeup\n");
  1248. restart:
  1249. msp3400_dbg("thread: restart scan\n");
  1250. msp->restart = 0;
  1251. if (kthread_should_stop())
  1252. break;
  1253. /* setup the chip*/
  1254. msp34xxg_reset(client);
  1255. std = standard;
  1256. if (std != 0x01)
  1257. goto unmute;
  1258. /* watch autodetect */
  1259. msp3400_dbg("triggered autodetect, waiting for result\n");
  1260. for (i = 0; i < 10; i++) {
  1261. if (msp34xx_sleep(msp,100))
  1262. goto restart;
  1263. /* check results */
  1264. val = msp3400c_read(client, I2C_MSP3400C_DEM, 0x7e);
  1265. if (val < 0x07ff) {
  1266. std = val;
  1267. break;
  1268. }
  1269. msp3400_dbg("detection still in progress\n");
  1270. }
  1271. if (0x01 == std) {
  1272. msp3400_dbg("detection still in progress after 10 tries. giving up.\n");
  1273. continue;
  1274. }
  1275. unmute:
  1276. msp3400_dbg("current mode: %s (0x%04x)\n",
  1277. msp34xx_standard_mode_name(std), std);
  1278. /* unmute: dispatch sound to scart output, set scart volume */
  1279. msp3400_dbg("unmute\n");
  1280. msp3400c_setbass(client, msp->bass);
  1281. msp3400c_settreble(client, msp->treble);
  1282. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1283. /* restore ACB */
  1284. if (msp3400c_write(client,
  1285. I2C_MSP3400C_DFP,
  1286. 0x13, /* ACB */
  1287. msp->acb))
  1288. return -1;
  1289. msp3400c_write(client,I2C_MSP3400C_DEM, 0x40, msp->i2s_mode);
  1290. }
  1291. msp3400_dbg("thread: exit\n");
  1292. return 0;
  1293. }
  1294. /* set the same 'source' for the loudspeaker, scart and quasi-peak detector
  1295. * the value for source is the same as bit 15:8 of DFP registers 0x08,
  1296. * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B
  1297. *
  1298. * this function replaces msp3400c_setstereo
  1299. */
  1300. static void msp34xxg_set_source(struct i2c_client *client, int source)
  1301. {
  1302. struct msp3400c *msp = i2c_get_clientdata(client);
  1303. /* fix matrix mode to stereo and let the msp choose what
  1304. * to output according to 'source', as recommended
  1305. * for MONO (source==0) downmixing set bit[7:0] to 0x30
  1306. */
  1307. int value = (source&0x07)<<8|(source==0 ? 0x30:0x20);
  1308. msp3400_dbg("set source to %d (0x%x)\n", source, value);
  1309. msp3400c_write(client,
  1310. I2C_MSP3400C_DFP,
  1311. 0x08, /* Loudspeaker Output */
  1312. value);
  1313. msp3400c_write(client,
  1314. I2C_MSP3400C_DFP,
  1315. 0x0a, /* SCART1 DA Output */
  1316. value);
  1317. msp3400c_write(client,
  1318. I2C_MSP3400C_DFP,
  1319. 0x0c, /* Quasi-peak detector */
  1320. value);
  1321. /*
  1322. * set identification threshold. Personally, I
  1323. * I set it to a higher value that the default
  1324. * of 0x190 to ignore noisy stereo signals.
  1325. * this needs tuning. (recommended range 0x00a0-0x03c0)
  1326. * 0x7f0 = forced mono mode
  1327. */
  1328. msp3400c_write(client,
  1329. I2C_MSP3400C_DEM,
  1330. 0x22, /* a2 threshold for stereo/bilingual */
  1331. stereo_threshold);
  1332. msp->source=source;
  1333. }
  1334. static void msp34xxg_detect_stereo(struct i2c_client *client)
  1335. {
  1336. struct msp3400c *msp = i2c_get_clientdata(client);
  1337. int status = msp3400c_read(client,
  1338. I2C_MSP3400C_DEM,
  1339. 0x0200 /* STATUS */);
  1340. int is_bilingual = status&0x100;
  1341. int is_stereo = status&0x40;
  1342. msp->rxsubchans = 0;
  1343. if (is_stereo)
  1344. msp->rxsubchans |= V4L2_TUNER_SUB_STEREO;
  1345. else
  1346. msp->rxsubchans |= V4L2_TUNER_SUB_MONO;
  1347. if (is_bilingual) {
  1348. msp->rxsubchans |= V4L2_TUNER_SUB_LANG1|V4L2_TUNER_SUB_LANG2;
  1349. /* I'm supposed to check whether it's SAP or not
  1350. * and set only LANG2/SAP in this case. Yet, the MSP
  1351. * does a lot of work to hide this and handle everything
  1352. * the same way. I don't want to work around it so unless
  1353. * this is a problem, I'll handle SAP just like lang1/lang2.
  1354. */
  1355. }
  1356. msp3400_dbg("status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
  1357. status, is_stereo, is_bilingual, msp->rxsubchans);
  1358. }
  1359. static void msp34xxg_set_audmode(struct i2c_client *client, int audmode)
  1360. {
  1361. struct msp3400c *msp = i2c_get_clientdata(client);
  1362. int source;
  1363. switch (audmode) {
  1364. case V4L2_TUNER_MODE_MONO:
  1365. source=0; /* mono only */
  1366. break;
  1367. case V4L2_TUNER_MODE_STEREO:
  1368. source=1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */
  1369. /* problem: that could also mean 2 (scart input) */
  1370. break;
  1371. case V4L2_TUNER_MODE_LANG1:
  1372. source=3; /* stereo or A */
  1373. break;
  1374. case V4L2_TUNER_MODE_LANG2:
  1375. source=4; /* stereo or B */
  1376. break;
  1377. default:
  1378. audmode = 0;
  1379. source = 1;
  1380. break;
  1381. }
  1382. msp->audmode = audmode;
  1383. msp34xxg_set_source(client, source);
  1384. }
  1385. /* ----------------------------------------------------------------------- */
  1386. static int msp_attach(struct i2c_adapter *adap, int addr, int kind);
  1387. static int msp_detach(struct i2c_client *client);
  1388. static int msp_probe(struct i2c_adapter *adap);
  1389. static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
  1390. static int msp_suspend(struct device * dev, pm_message_t state);
  1391. static int msp_resume(struct device * dev);
  1392. static void msp_wake_thread(struct i2c_client *client);
  1393. static struct i2c_driver driver = {
  1394. .id = I2C_DRIVERID_MSP3400,
  1395. .attach_adapter = msp_probe,
  1396. .detach_client = msp_detach,
  1397. .command = msp_command,
  1398. .driver = {
  1399. .name = "i2c msp3400 driver",
  1400. .suspend = msp_suspend,
  1401. .resume = msp_resume,
  1402. },
  1403. };
  1404. static struct i2c_client client_template =
  1405. {
  1406. .name = "(unset)",
  1407. .driver = &driver,
  1408. };
  1409. static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
  1410. {
  1411. struct msp3400c *msp;
  1412. struct i2c_client *client = &client_template;
  1413. int (*thread_func)(void *data) = NULL;
  1414. int i;
  1415. client_template.adapter = adap;
  1416. client_template.addr = addr;
  1417. if (-1 == msp3400c_reset(&client_template)) {
  1418. msp3400_dbg("no chip found\n");
  1419. return -1;
  1420. }
  1421. if (NULL == (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
  1422. return -ENOMEM;
  1423. memcpy(client,&client_template,sizeof(struct i2c_client));
  1424. if (NULL == (msp = kmalloc(sizeof(struct msp3400c),GFP_KERNEL))) {
  1425. kfree(client);
  1426. return -ENOMEM;
  1427. }
  1428. memset(msp,0,sizeof(struct msp3400c));
  1429. msp->norm = VIDEO_MODE_NTSC;
  1430. msp->left = 58880; /* 0db gain */
  1431. msp->right = 58880; /* 0db gain */
  1432. msp->bass = 32768;
  1433. msp->treble = 32768;
  1434. msp->input = -1;
  1435. msp->muted = 0;
  1436. msp->i2s_mode = 0;
  1437. for (i = 0; i < DFP_COUNT; i++)
  1438. msp->dfp_regs[i] = -1;
  1439. i2c_set_clientdata(client, msp);
  1440. init_waitqueue_head(&msp->wq);
  1441. if (-1 == msp3400c_reset(client)) {
  1442. kfree(msp);
  1443. kfree(client);
  1444. msp3400_dbg("no chip found\n");
  1445. return -1;
  1446. }
  1447. msp->rev1 = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1e);
  1448. if (-1 != msp->rev1)
  1449. msp->rev2 = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1f);
  1450. if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) {
  1451. kfree(msp);
  1452. kfree(client);
  1453. msp3400_dbg("error while reading chip version\n");
  1454. return -1;
  1455. }
  1456. msp3400_dbg("rev1=0x%04x, rev2=0x%04x\n", msp->rev1, msp->rev2);
  1457. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1458. snprintf(client->name, sizeof(client->name), "MSP%c4%02d%c-%c%d",
  1459. ((msp->rev1>>4)&0x0f) + '3',
  1460. (msp->rev2>>8)&0xff, (msp->rev1&0x0f)+'@',
  1461. ((msp->rev1>>8)&0xff)+'@', msp->rev2&0x1f);
  1462. msp->opmode = opmode;
  1463. if (OPMODE_AUTO == msp->opmode) {
  1464. if (HAVE_SIMPLER(msp))
  1465. msp->opmode = OPMODE_SIMPLER;
  1466. else if (HAVE_SIMPLE(msp))
  1467. msp->opmode = OPMODE_SIMPLE;
  1468. else
  1469. msp->opmode = OPMODE_MANUAL;
  1470. }
  1471. /* hello world :-) */
  1472. msp3400_info("chip=%s", client->name);
  1473. if (HAVE_NICAM(msp))
  1474. printk(" +nicam");
  1475. if (HAVE_SIMPLE(msp))
  1476. printk(" +simple");
  1477. if (HAVE_SIMPLER(msp))
  1478. printk(" +simpler");
  1479. if (HAVE_RADIO(msp))
  1480. printk(" +radio");
  1481. /* version-specific initialization */
  1482. switch (msp->opmode) {
  1483. case OPMODE_MANUAL:
  1484. printk(" mode=manual");
  1485. thread_func = msp3400c_thread;
  1486. break;
  1487. case OPMODE_SIMPLE:
  1488. printk(" mode=simple");
  1489. thread_func = msp3410d_thread;
  1490. break;
  1491. case OPMODE_SIMPLER:
  1492. printk(" mode=simpler");
  1493. thread_func = msp34xxg_thread;
  1494. break;
  1495. }
  1496. printk("\n");
  1497. /* startup control thread if needed */
  1498. if (thread_func) {
  1499. msp->kthread = kthread_run(thread_func, client, "msp34xx");
  1500. if (NULL == msp->kthread)
  1501. msp3400_warn("kernel_thread() failed\n");
  1502. msp_wake_thread(client);
  1503. }
  1504. /* done */
  1505. i2c_attach_client(client);
  1506. /* update our own array */
  1507. for (i = 0; i < MSP3400_MAX; i++) {
  1508. if (NULL == msps[i]) {
  1509. msps[i] = client;
  1510. break;
  1511. }
  1512. }
  1513. return 0;
  1514. }
  1515. static int msp_detach(struct i2c_client *client)
  1516. {
  1517. struct msp3400c *msp = i2c_get_clientdata(client);
  1518. int i;
  1519. /* shutdown control thread */
  1520. if (msp->kthread) {
  1521. msp->restart = 1;
  1522. kthread_stop(msp->kthread);
  1523. }
  1524. msp3400c_reset(client);
  1525. /* update our own array */
  1526. for (i = 0; i < MSP3400_MAX; i++) {
  1527. if (client == msps[i]) {
  1528. msps[i] = NULL;
  1529. break;
  1530. }
  1531. }
  1532. i2c_detach_client(client);
  1533. kfree(msp);
  1534. kfree(client);
  1535. return 0;
  1536. }
  1537. static int msp_probe(struct i2c_adapter *adap)
  1538. {
  1539. if (adap->class & I2C_CLASS_TV_ANALOG)
  1540. return i2c_probe(adap, &addr_data, msp_attach);
  1541. return 0;
  1542. }
  1543. static void msp_wake_thread(struct i2c_client *client)
  1544. {
  1545. struct msp3400c *msp = i2c_get_clientdata(client);
  1546. if (NULL == msp->kthread)
  1547. return;
  1548. msp3400c_setvolume(client,msp->muted,0,0);
  1549. msp->watch_stereo = 0;
  1550. msp->restart = 1;
  1551. wake_up_interruptible(&msp->wq);
  1552. }
  1553. /* ----------------------------------------------------------------------- */
  1554. static int mode_v4l2_to_v4l1(int rxsubchans)
  1555. {
  1556. int mode = 0;
  1557. if (rxsubchans & V4L2_TUNER_SUB_STEREO)
  1558. mode |= VIDEO_SOUND_STEREO;
  1559. if (rxsubchans & V4L2_TUNER_SUB_LANG2)
  1560. mode |= VIDEO_SOUND_LANG2;
  1561. if (rxsubchans & V4L2_TUNER_SUB_LANG1)
  1562. mode |= VIDEO_SOUND_LANG1;
  1563. if (0 == mode)
  1564. mode |= VIDEO_SOUND_MONO;
  1565. return mode;
  1566. }
  1567. static int mode_v4l1_to_v4l2(int mode)
  1568. {
  1569. if (mode & VIDEO_SOUND_STEREO)
  1570. return V4L2_TUNER_MODE_STEREO;
  1571. if (mode & VIDEO_SOUND_LANG2)
  1572. return V4L2_TUNER_MODE_LANG2;
  1573. if (mode & VIDEO_SOUND_LANG1)
  1574. return V4L2_TUNER_MODE_LANG1;
  1575. return V4L2_TUNER_MODE_MONO;
  1576. }
  1577. static void msp_any_detect_stereo(struct i2c_client *client)
  1578. {
  1579. struct msp3400c *msp = i2c_get_clientdata(client);
  1580. switch (msp->opmode) {
  1581. case OPMODE_MANUAL:
  1582. case OPMODE_SIMPLE:
  1583. autodetect_stereo(client);
  1584. break;
  1585. case OPMODE_SIMPLER:
  1586. msp34xxg_detect_stereo(client);
  1587. break;
  1588. }
  1589. }
  1590. static void msp_any_set_audmode(struct i2c_client *client, int audmode)
  1591. {
  1592. struct msp3400c *msp = i2c_get_clientdata(client);
  1593. switch (msp->opmode) {
  1594. case OPMODE_MANUAL:
  1595. case OPMODE_SIMPLE:
  1596. msp->watch_stereo = 0;
  1597. msp3400c_setstereo(client, audmode);
  1598. break;
  1599. case OPMODE_SIMPLER:
  1600. msp34xxg_set_audmode(client, audmode);
  1601. break;
  1602. }
  1603. }
  1604. static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
  1605. {
  1606. struct msp3400c *msp = i2c_get_clientdata(client);
  1607. __u16 *sarg = arg;
  1608. int scart = 0;
  1609. switch (cmd) {
  1610. case AUDC_SET_INPUT:
  1611. msp3400_dbg("AUDC_SET_INPUT(%d)\n",*sarg);
  1612. if (*sarg == msp->input)
  1613. break;
  1614. msp->input = *sarg;
  1615. switch (*sarg) {
  1616. case AUDIO_RADIO:
  1617. /* Hauppauge uses IN2 for the radio */
  1618. msp->mode = MSP_MODE_FM_RADIO;
  1619. scart = SCART_IN2;
  1620. break;
  1621. case AUDIO_EXTERN_1:
  1622. /* IN1 is often used for external input ... */
  1623. msp->mode = MSP_MODE_EXTERN;
  1624. scart = SCART_IN1;
  1625. break;
  1626. case AUDIO_EXTERN_2:
  1627. /* ... sometimes it is IN2 through ;) */
  1628. msp->mode = MSP_MODE_EXTERN;
  1629. scart = SCART_IN2;
  1630. break;
  1631. case AUDIO_TUNER:
  1632. msp->mode = -1;
  1633. break;
  1634. default:
  1635. if (*sarg & AUDIO_MUTE)
  1636. msp3400c_set_scart(client,SCART_MUTE,0);
  1637. break;
  1638. }
  1639. if (scart) {
  1640. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1641. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1642. msp3400c_set_scart(client,scart,0);
  1643. msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
  1644. if (msp->opmode != OPMODE_SIMPLER)
  1645. msp3400c_setstereo(client, msp->audmode);
  1646. }
  1647. msp_wake_thread(client);
  1648. break;
  1649. case AUDC_SET_RADIO:
  1650. msp3400_dbg("AUDC_SET_RADIO\n");
  1651. msp->norm = VIDEO_MODE_RADIO;
  1652. msp3400_dbg("switching to radio mode\n");
  1653. msp->watch_stereo = 0;
  1654. switch (msp->opmode) {
  1655. case OPMODE_MANUAL:
  1656. /* set msp3400 to FM radio mode */
  1657. msp3400c_setmode(client,MSP_MODE_FM_RADIO);
  1658. msp3400c_setcarrier(client, MSP_CARRIER(10.7),
  1659. MSP_CARRIER(10.7));
  1660. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1661. break;
  1662. case OPMODE_SIMPLE:
  1663. case OPMODE_SIMPLER:
  1664. /* the thread will do for us */
  1665. msp_wake_thread(client);
  1666. break;
  1667. }
  1668. break;
  1669. /* work-in-progress: hook to control the DFP registers */
  1670. case MSP_SET_DFPREG:
  1671. {
  1672. struct msp_dfpreg *r = arg;
  1673. int i;
  1674. if (r->reg < 0 || r->reg >= DFP_COUNT)
  1675. return -EINVAL;
  1676. for (i = 0; i < sizeof(bl_dfp) / sizeof(int); i++)
  1677. if (r->reg == bl_dfp[i])
  1678. return -EINVAL;
  1679. msp->dfp_regs[r->reg] = r->value;
  1680. msp3400c_write(client, I2C_MSP3400C_DFP, r->reg, r->value);
  1681. return 0;
  1682. }
  1683. case MSP_GET_DFPREG:
  1684. {
  1685. struct msp_dfpreg *r = arg;
  1686. if (r->reg < 0 || r->reg >= DFP_COUNT)
  1687. return -EINVAL;
  1688. r->value = msp3400c_read(client, I2C_MSP3400C_DFP, r->reg);
  1689. return 0;
  1690. }
  1691. /* --- v4l ioctls --- */
  1692. /* take care: bttv does userspace copying, we'll get a
  1693. kernel pointer here... */
  1694. case VIDIOCGAUDIO:
  1695. {
  1696. struct video_audio *va = arg;
  1697. msp3400_dbg("VIDIOCGAUDIO\n");
  1698. va->flags |= VIDEO_AUDIO_VOLUME |
  1699. VIDEO_AUDIO_BASS |
  1700. VIDEO_AUDIO_TREBLE |
  1701. VIDEO_AUDIO_MUTABLE;
  1702. if (msp->muted)
  1703. va->flags |= VIDEO_AUDIO_MUTE;
  1704. if (msp->muted)
  1705. va->flags |= VIDEO_AUDIO_MUTE;
  1706. va->volume = MAX(msp->left, msp->right);
  1707. va->balance = (32768 * MIN(msp->left, msp->right)) /
  1708. (va->volume ? va->volume : 1);
  1709. va->balance = (msp->left < msp->right) ?
  1710. (65535 - va->balance) : va->balance;
  1711. if (0 == va->volume)
  1712. va->balance = 32768;
  1713. va->bass = msp->bass;
  1714. va->treble = msp->treble;
  1715. msp_any_detect_stereo(client);
  1716. va->mode = mode_v4l2_to_v4l1(msp->rxsubchans);
  1717. break;
  1718. }
  1719. case VIDIOCSAUDIO:
  1720. {
  1721. struct video_audio *va = arg;
  1722. msp3400_dbg("VIDIOCSAUDIO\n");
  1723. msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
  1724. msp->left = (MIN(65536 - va->balance, 32768) *
  1725. va->volume) / 32768;
  1726. msp->right = (MIN(va->balance, 32768) * va->volume) / 32768;
  1727. msp->bass = va->bass;
  1728. msp->treble = va->treble;
  1729. msp3400_dbg("VIDIOCSAUDIO setting va->volume to %d\n",
  1730. va->volume);
  1731. msp3400_dbg("VIDIOCSAUDIO setting va->balance to %d\n",
  1732. va->balance);
  1733. msp3400_dbg("VIDIOCSAUDIO setting va->flags to %d\n",
  1734. va->flags);
  1735. msp3400_dbg("VIDIOCSAUDIO setting msp->left to %d\n",
  1736. msp->left);
  1737. msp3400_dbg("VIDIOCSAUDIO setting msp->right to %d\n",
  1738. msp->right);
  1739. msp3400_dbg("VIDIOCSAUDIO setting msp->bass to %d\n",
  1740. msp->bass);
  1741. msp3400_dbg("VIDIOCSAUDIO setting msp->treble to %d\n",
  1742. msp->treble);
  1743. msp3400_dbg("VIDIOCSAUDIO setting msp->mode to %d\n",
  1744. msp->mode);
  1745. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1746. msp3400c_setbass(client, msp->bass);
  1747. msp3400c_settreble(client, msp->treble);
  1748. if (va->mode != 0 && msp->norm != VIDEO_MODE_RADIO)
  1749. msp_any_set_audmode(client,mode_v4l1_to_v4l2(va->mode));
  1750. break;
  1751. }
  1752. case VIDIOCSCHAN:
  1753. {
  1754. struct video_channel *vc = arg;
  1755. msp3400_dbg("VIDIOCSCHAN (norm=%d)\n",vc->norm);
  1756. msp->norm = vc->norm;
  1757. msp_wake_thread(client);
  1758. break;
  1759. }
  1760. case VIDIOCSFREQ:
  1761. case VIDIOC_S_FREQUENCY:
  1762. {
  1763. /* new channel -- kick audio carrier scan */
  1764. msp3400_dbg("VIDIOCSFREQ\n");
  1765. msp_wake_thread(client);
  1766. break;
  1767. }
  1768. /* msp34xx specific */
  1769. case MSP_SET_MATRIX:
  1770. {
  1771. struct msp_matrix *mspm = arg;
  1772. msp3400_dbg("MSP_SET_MATRIX\n");
  1773. msp3400c_set_scart(client, mspm->input, mspm->output);
  1774. break;
  1775. }
  1776. /* --- v4l2 ioctls --- */
  1777. case VIDIOC_S_STD:
  1778. {
  1779. v4l2_std_id *id = arg;
  1780. /*FIXME: use V4L2 mode flags on msp3400 instead of V4L1*/
  1781. if (*id & V4L2_STD_PAL) {
  1782. msp->norm=VIDEO_MODE_PAL;
  1783. } else if (*id & V4L2_STD_SECAM) {
  1784. msp->norm=VIDEO_MODE_SECAM;
  1785. } else {
  1786. msp->norm=VIDEO_MODE_NTSC;
  1787. }
  1788. msp_wake_thread(client);
  1789. return 0;
  1790. }
  1791. case VIDIOC_ENUMINPUT:
  1792. {
  1793. struct v4l2_input *i = arg;
  1794. if (i->index != 0)
  1795. return -EINVAL;
  1796. i->type = V4L2_INPUT_TYPE_TUNER;
  1797. switch (i->index) {
  1798. case AUDIO_RADIO:
  1799. strcpy(i->name,"Radio");
  1800. break;
  1801. case AUDIO_EXTERN_1:
  1802. strcpy(i->name,"Extern 1");
  1803. break;
  1804. case AUDIO_EXTERN_2:
  1805. strcpy(i->name,"Extern 2");
  1806. break;
  1807. case AUDIO_TUNER:
  1808. strcpy(i->name,"Television");
  1809. break;
  1810. default:
  1811. return -EINVAL;
  1812. }
  1813. return 0;
  1814. }
  1815. case VIDIOC_G_AUDIO:
  1816. {
  1817. struct v4l2_audio *a = arg;
  1818. memset(a,0,sizeof(*a));
  1819. switch (a->index) {
  1820. case AUDIO_RADIO:
  1821. strcpy(a->name,"Radio");
  1822. break;
  1823. case AUDIO_EXTERN_1:
  1824. strcpy(a->name,"Extern 1");
  1825. break;
  1826. case AUDIO_EXTERN_2:
  1827. strcpy(a->name,"Extern 2");
  1828. break;
  1829. case AUDIO_TUNER:
  1830. strcpy(a->name,"Television");
  1831. break;
  1832. default:
  1833. return -EINVAL;
  1834. }
  1835. msp_any_detect_stereo(client);
  1836. if (msp->audmode == V4L2_TUNER_MODE_STEREO) {
  1837. a->capability=V4L2_AUDCAP_STEREO;
  1838. }
  1839. break;
  1840. }
  1841. case VIDIOC_S_AUDIO:
  1842. {
  1843. struct v4l2_audio *sarg = arg;
  1844. switch (sarg->index) {
  1845. case AUDIO_RADIO:
  1846. /* Hauppauge uses IN2 for the radio */
  1847. msp->mode = MSP_MODE_FM_RADIO;
  1848. scart = SCART_IN2;
  1849. break;
  1850. case AUDIO_EXTERN_1:
  1851. /* IN1 is often used for external input ... */
  1852. msp->mode = MSP_MODE_EXTERN;
  1853. scart = SCART_IN1;
  1854. break;
  1855. case AUDIO_EXTERN_2:
  1856. /* ... sometimes it is IN2 through ;) */
  1857. msp->mode = MSP_MODE_EXTERN;
  1858. scart = SCART_IN2;
  1859. break;
  1860. case AUDIO_TUNER:
  1861. msp->mode = -1;
  1862. break;
  1863. }
  1864. if (scart) {
  1865. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1866. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1867. msp3400c_set_scart(client,scart,0);
  1868. msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
  1869. }
  1870. if (sarg->capability==V4L2_AUDCAP_STEREO) {
  1871. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1872. } else {
  1873. msp->audmode &= ~V4L2_TUNER_MODE_STEREO;
  1874. }
  1875. msp_any_set_audmode(client, msp->audmode);
  1876. msp_wake_thread(client);
  1877. break;
  1878. }
  1879. case VIDIOC_G_TUNER:
  1880. {
  1881. struct v4l2_tuner *vt = arg;
  1882. msp_any_detect_stereo(client);
  1883. vt->audmode = msp->audmode;
  1884. vt->rxsubchans = msp->rxsubchans;
  1885. vt->capability = V4L2_TUNER_CAP_STEREO |
  1886. V4L2_TUNER_CAP_LANG1|
  1887. V4L2_TUNER_CAP_LANG2;
  1888. break;
  1889. }
  1890. case VIDIOC_S_TUNER:
  1891. {
  1892. struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
  1893. /* only set audmode */
  1894. if (vt->audmode != -1 && vt->audmode != 0)
  1895. msp_any_set_audmode(client, vt->audmode);
  1896. break;
  1897. }
  1898. case VIDIOC_G_AUDOUT:
  1899. {
  1900. struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
  1901. int idx=a->index;
  1902. memset(a,0,sizeof(*a));
  1903. switch (idx) {
  1904. case 0:
  1905. strcpy(a->name,"Scart1 Out");
  1906. break;
  1907. case 1:
  1908. strcpy(a->name,"Scart2 Out");
  1909. break;
  1910. case 2:
  1911. strcpy(a->name,"I2S Out");
  1912. break;
  1913. default:
  1914. return -EINVAL;
  1915. }
  1916. break;
  1917. }
  1918. case VIDIOC_S_AUDOUT:
  1919. {
  1920. struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
  1921. if (a->index<0||a->index>2)
  1922. return -EINVAL;
  1923. if (a->index==2) {
  1924. if (a->mode == V4L2_AUDMODE_32BITS)
  1925. msp->i2s_mode=1;
  1926. else
  1927. msp->i2s_mode=0;
  1928. }
  1929. msp3400_dbg("Setting audio out on msp34xx to input %i, mode %i\n",
  1930. a->index,msp->i2s_mode);
  1931. msp3400c_set_scart(client,msp->in_scart,a->index+1);
  1932. break;
  1933. }
  1934. default:
  1935. /* nothing */
  1936. break;
  1937. }
  1938. return 0;
  1939. }
  1940. static int msp_suspend(struct device * dev, pm_message_t state)
  1941. {
  1942. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  1943. msp3400_dbg("msp34xx: suspend\n");
  1944. msp3400c_reset(client);
  1945. return 0;
  1946. }
  1947. static int msp_resume(struct device * dev)
  1948. {
  1949. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  1950. msp3400_dbg("msp34xx: resume\n");
  1951. msp_wake_thread(client);
  1952. return 0;
  1953. }
  1954. /* ----------------------------------------------------------------------- */
  1955. static int __init msp3400_init_module(void)
  1956. {
  1957. return i2c_add_driver(&driver);
  1958. }
  1959. static void __exit msp3400_cleanup_module(void)
  1960. {
  1961. i2c_del_driver(&driver);
  1962. }
  1963. module_init(msp3400_init_module);
  1964. module_exit(msp3400_cleanup_module);
  1965. /*
  1966. * Overrides for Emacs so that we follow Linus's tabbing style.
  1967. * ---------------------------------------------------------------------------
  1968. * Local variables:
  1969. * c-basic-offset: 8
  1970. * End:
  1971. */