msp3400.c 60 KB

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