msp3400.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  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. .flags = I2C_CLIENT_ALLOW_USE,
  1406. .driver = &driver,
  1407. };
  1408. static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
  1409. {
  1410. struct msp3400c *msp;
  1411. struct i2c_client *client = &client_template;
  1412. int (*thread_func)(void *data) = NULL;
  1413. int i;
  1414. client_template.adapter = adap;
  1415. client_template.addr = addr;
  1416. if (-1 == msp3400c_reset(&client_template)) {
  1417. msp3400_dbg("no chip found\n");
  1418. return -1;
  1419. }
  1420. if (NULL == (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
  1421. return -ENOMEM;
  1422. memcpy(client,&client_template,sizeof(struct i2c_client));
  1423. if (NULL == (msp = kmalloc(sizeof(struct msp3400c),GFP_KERNEL))) {
  1424. kfree(client);
  1425. return -ENOMEM;
  1426. }
  1427. memset(msp,0,sizeof(struct msp3400c));
  1428. msp->norm = VIDEO_MODE_NTSC;
  1429. msp->left = 58880; /* 0db gain */
  1430. msp->right = 58880; /* 0db gain */
  1431. msp->bass = 32768;
  1432. msp->treble = 32768;
  1433. msp->input = -1;
  1434. msp->muted = 0;
  1435. msp->i2s_mode = 0;
  1436. for (i = 0; i < DFP_COUNT; i++)
  1437. msp->dfp_regs[i] = -1;
  1438. i2c_set_clientdata(client, msp);
  1439. init_waitqueue_head(&msp->wq);
  1440. if (-1 == msp3400c_reset(client)) {
  1441. kfree(msp);
  1442. kfree(client);
  1443. msp3400_dbg("no chip found\n");
  1444. return -1;
  1445. }
  1446. msp->rev1 = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1e);
  1447. if (-1 != msp->rev1)
  1448. msp->rev2 = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1f);
  1449. if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) {
  1450. kfree(msp);
  1451. kfree(client);
  1452. msp3400_dbg("error while reading chip version\n");
  1453. return -1;
  1454. }
  1455. msp3400_dbg("rev1=0x%04x, rev2=0x%04x\n", msp->rev1, msp->rev2);
  1456. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1457. snprintf(client->name, sizeof(client->name), "MSP%c4%02d%c-%c%d",
  1458. ((msp->rev1>>4)&0x0f) + '3',
  1459. (msp->rev2>>8)&0xff, (msp->rev1&0x0f)+'@',
  1460. ((msp->rev1>>8)&0xff)+'@', msp->rev2&0x1f);
  1461. msp->opmode = opmode;
  1462. if (OPMODE_AUTO == msp->opmode) {
  1463. if (HAVE_SIMPLER(msp))
  1464. msp->opmode = OPMODE_SIMPLER;
  1465. else if (HAVE_SIMPLE(msp))
  1466. msp->opmode = OPMODE_SIMPLE;
  1467. else
  1468. msp->opmode = OPMODE_MANUAL;
  1469. }
  1470. /* hello world :-) */
  1471. msp3400_info("chip=%s", client->name);
  1472. if (HAVE_NICAM(msp))
  1473. printk(" +nicam");
  1474. if (HAVE_SIMPLE(msp))
  1475. printk(" +simple");
  1476. if (HAVE_SIMPLER(msp))
  1477. printk(" +simpler");
  1478. if (HAVE_RADIO(msp))
  1479. printk(" +radio");
  1480. /* version-specific initialization */
  1481. switch (msp->opmode) {
  1482. case OPMODE_MANUAL:
  1483. printk(" mode=manual");
  1484. thread_func = msp3400c_thread;
  1485. break;
  1486. case OPMODE_SIMPLE:
  1487. printk(" mode=simple");
  1488. thread_func = msp3410d_thread;
  1489. break;
  1490. case OPMODE_SIMPLER:
  1491. printk(" mode=simpler");
  1492. thread_func = msp34xxg_thread;
  1493. break;
  1494. }
  1495. printk("\n");
  1496. /* startup control thread if needed */
  1497. if (thread_func) {
  1498. msp->kthread = kthread_run(thread_func, client, "msp34xx");
  1499. if (NULL == msp->kthread)
  1500. msp3400_warn("kernel_thread() failed\n");
  1501. msp_wake_thread(client);
  1502. }
  1503. /* done */
  1504. i2c_attach_client(client);
  1505. /* update our own array */
  1506. for (i = 0; i < MSP3400_MAX; i++) {
  1507. if (NULL == msps[i]) {
  1508. msps[i] = client;
  1509. break;
  1510. }
  1511. }
  1512. return 0;
  1513. }
  1514. static int msp_detach(struct i2c_client *client)
  1515. {
  1516. struct msp3400c *msp = i2c_get_clientdata(client);
  1517. int i;
  1518. /* shutdown control thread */
  1519. if (msp->kthread) {
  1520. msp->restart = 1;
  1521. kthread_stop(msp->kthread);
  1522. }
  1523. msp3400c_reset(client);
  1524. /* update our own array */
  1525. for (i = 0; i < MSP3400_MAX; i++) {
  1526. if (client == msps[i]) {
  1527. msps[i] = NULL;
  1528. break;
  1529. }
  1530. }
  1531. i2c_detach_client(client);
  1532. kfree(msp);
  1533. kfree(client);
  1534. return 0;
  1535. }
  1536. static int msp_probe(struct i2c_adapter *adap)
  1537. {
  1538. if (adap->class & I2C_CLASS_TV_ANALOG)
  1539. return i2c_probe(adap, &addr_data, msp_attach);
  1540. return 0;
  1541. }
  1542. static void msp_wake_thread(struct i2c_client *client)
  1543. {
  1544. struct msp3400c *msp = i2c_get_clientdata(client);
  1545. if (NULL == msp->kthread)
  1546. return;
  1547. msp3400c_setvolume(client,msp->muted,0,0);
  1548. msp->watch_stereo = 0;
  1549. msp->restart = 1;
  1550. wake_up_interruptible(&msp->wq);
  1551. }
  1552. /* ----------------------------------------------------------------------- */
  1553. static int mode_v4l2_to_v4l1(int rxsubchans)
  1554. {
  1555. int mode = 0;
  1556. if (rxsubchans & V4L2_TUNER_SUB_STEREO)
  1557. mode |= VIDEO_SOUND_STEREO;
  1558. if (rxsubchans & V4L2_TUNER_SUB_LANG2)
  1559. mode |= VIDEO_SOUND_LANG2;
  1560. if (rxsubchans & V4L2_TUNER_SUB_LANG1)
  1561. mode |= VIDEO_SOUND_LANG1;
  1562. if (0 == mode)
  1563. mode |= VIDEO_SOUND_MONO;
  1564. return mode;
  1565. }
  1566. static int mode_v4l1_to_v4l2(int mode)
  1567. {
  1568. if (mode & VIDEO_SOUND_STEREO)
  1569. return V4L2_TUNER_MODE_STEREO;
  1570. if (mode & VIDEO_SOUND_LANG2)
  1571. return V4L2_TUNER_MODE_LANG2;
  1572. if (mode & VIDEO_SOUND_LANG1)
  1573. return V4L2_TUNER_MODE_LANG1;
  1574. return V4L2_TUNER_MODE_MONO;
  1575. }
  1576. static void msp_any_detect_stereo(struct i2c_client *client)
  1577. {
  1578. struct msp3400c *msp = i2c_get_clientdata(client);
  1579. switch (msp->opmode) {
  1580. case OPMODE_MANUAL:
  1581. case OPMODE_SIMPLE:
  1582. autodetect_stereo(client);
  1583. break;
  1584. case OPMODE_SIMPLER:
  1585. msp34xxg_detect_stereo(client);
  1586. break;
  1587. }
  1588. }
  1589. static void msp_any_set_audmode(struct i2c_client *client, int audmode)
  1590. {
  1591. struct msp3400c *msp = i2c_get_clientdata(client);
  1592. switch (msp->opmode) {
  1593. case OPMODE_MANUAL:
  1594. case OPMODE_SIMPLE:
  1595. msp->watch_stereo = 0;
  1596. msp3400c_setstereo(client, audmode);
  1597. break;
  1598. case OPMODE_SIMPLER:
  1599. msp34xxg_set_audmode(client, audmode);
  1600. break;
  1601. }
  1602. }
  1603. static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
  1604. {
  1605. struct msp3400c *msp = i2c_get_clientdata(client);
  1606. __u16 *sarg = arg;
  1607. int scart = 0;
  1608. switch (cmd) {
  1609. case AUDC_SET_INPUT:
  1610. msp3400_dbg("AUDC_SET_INPUT(%d)\n",*sarg);
  1611. if (*sarg == msp->input)
  1612. break;
  1613. msp->input = *sarg;
  1614. switch (*sarg) {
  1615. case AUDIO_RADIO:
  1616. /* Hauppauge uses IN2 for the radio */
  1617. msp->mode = MSP_MODE_FM_RADIO;
  1618. scart = SCART_IN2;
  1619. break;
  1620. case AUDIO_EXTERN_1:
  1621. /* IN1 is often used for external input ... */
  1622. msp->mode = MSP_MODE_EXTERN;
  1623. scart = SCART_IN1;
  1624. break;
  1625. case AUDIO_EXTERN_2:
  1626. /* ... sometimes it is IN2 through ;) */
  1627. msp->mode = MSP_MODE_EXTERN;
  1628. scart = SCART_IN2;
  1629. break;
  1630. case AUDIO_TUNER:
  1631. msp->mode = -1;
  1632. break;
  1633. default:
  1634. if (*sarg & AUDIO_MUTE)
  1635. msp3400c_set_scart(client,SCART_MUTE,0);
  1636. break;
  1637. }
  1638. if (scart) {
  1639. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1640. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1641. msp3400c_set_scart(client,scart,0);
  1642. msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
  1643. if (msp->opmode != OPMODE_SIMPLER)
  1644. msp3400c_setstereo(client, msp->audmode);
  1645. }
  1646. msp_wake_thread(client);
  1647. break;
  1648. case AUDC_SET_RADIO:
  1649. msp3400_dbg("AUDC_SET_RADIO\n");
  1650. msp->norm = VIDEO_MODE_RADIO;
  1651. msp3400_dbg("switching to radio mode\n");
  1652. msp->watch_stereo = 0;
  1653. switch (msp->opmode) {
  1654. case OPMODE_MANUAL:
  1655. /* set msp3400 to FM radio mode */
  1656. msp3400c_setmode(client,MSP_MODE_FM_RADIO);
  1657. msp3400c_setcarrier(client, MSP_CARRIER(10.7),
  1658. MSP_CARRIER(10.7));
  1659. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1660. break;
  1661. case OPMODE_SIMPLE:
  1662. case OPMODE_SIMPLER:
  1663. /* the thread will do for us */
  1664. msp_wake_thread(client);
  1665. break;
  1666. }
  1667. break;
  1668. /* work-in-progress: hook to control the DFP registers */
  1669. case MSP_SET_DFPREG:
  1670. {
  1671. struct msp_dfpreg *r = arg;
  1672. int i;
  1673. if (r->reg < 0 || r->reg >= DFP_COUNT)
  1674. return -EINVAL;
  1675. for (i = 0; i < sizeof(bl_dfp) / sizeof(int); i++)
  1676. if (r->reg == bl_dfp[i])
  1677. return -EINVAL;
  1678. msp->dfp_regs[r->reg] = r->value;
  1679. msp3400c_write(client, I2C_MSP3400C_DFP, r->reg, r->value);
  1680. return 0;
  1681. }
  1682. case MSP_GET_DFPREG:
  1683. {
  1684. struct msp_dfpreg *r = arg;
  1685. if (r->reg < 0 || r->reg >= DFP_COUNT)
  1686. return -EINVAL;
  1687. r->value = msp3400c_read(client, I2C_MSP3400C_DFP, r->reg);
  1688. return 0;
  1689. }
  1690. /* --- v4l ioctls --- */
  1691. /* take care: bttv does userspace copying, we'll get a
  1692. kernel pointer here... */
  1693. case VIDIOCGAUDIO:
  1694. {
  1695. struct video_audio *va = arg;
  1696. msp3400_dbg("VIDIOCGAUDIO\n");
  1697. va->flags |= VIDEO_AUDIO_VOLUME |
  1698. VIDEO_AUDIO_BASS |
  1699. VIDEO_AUDIO_TREBLE |
  1700. VIDEO_AUDIO_MUTABLE;
  1701. if (msp->muted)
  1702. va->flags |= VIDEO_AUDIO_MUTE;
  1703. if (msp->muted)
  1704. va->flags |= VIDEO_AUDIO_MUTE;
  1705. va->volume = MAX(msp->left, msp->right);
  1706. va->balance = (32768 * MIN(msp->left, msp->right)) /
  1707. (va->volume ? va->volume : 1);
  1708. va->balance = (msp->left < msp->right) ?
  1709. (65535 - va->balance) : va->balance;
  1710. if (0 == va->volume)
  1711. va->balance = 32768;
  1712. va->bass = msp->bass;
  1713. va->treble = msp->treble;
  1714. msp_any_detect_stereo(client);
  1715. va->mode = mode_v4l2_to_v4l1(msp->rxsubchans);
  1716. break;
  1717. }
  1718. case VIDIOCSAUDIO:
  1719. {
  1720. struct video_audio *va = arg;
  1721. msp3400_dbg("VIDIOCSAUDIO\n");
  1722. msp->muted = (va->flags & VIDEO_AUDIO_MUTE);
  1723. msp->left = (MIN(65536 - va->balance, 32768) *
  1724. va->volume) / 32768;
  1725. msp->right = (MIN(va->balance, 32768) * va->volume) / 32768;
  1726. msp->bass = va->bass;
  1727. msp->treble = va->treble;
  1728. msp3400_dbg("VIDIOCSAUDIO setting va->volume to %d\n",
  1729. va->volume);
  1730. msp3400_dbg("VIDIOCSAUDIO setting va->balance to %d\n",
  1731. va->balance);
  1732. msp3400_dbg("VIDIOCSAUDIO setting va->flags to %d\n",
  1733. va->flags);
  1734. msp3400_dbg("VIDIOCSAUDIO setting msp->left to %d\n",
  1735. msp->left);
  1736. msp3400_dbg("VIDIOCSAUDIO setting msp->right to %d\n",
  1737. msp->right);
  1738. msp3400_dbg("VIDIOCSAUDIO setting msp->bass to %d\n",
  1739. msp->bass);
  1740. msp3400_dbg("VIDIOCSAUDIO setting msp->treble to %d\n",
  1741. msp->treble);
  1742. msp3400_dbg("VIDIOCSAUDIO setting msp->mode to %d\n",
  1743. msp->mode);
  1744. msp3400c_setvolume(client, msp->muted, msp->left, msp->right);
  1745. msp3400c_setbass(client, msp->bass);
  1746. msp3400c_settreble(client, msp->treble);
  1747. if (va->mode != 0 && msp->norm != VIDEO_MODE_RADIO)
  1748. msp_any_set_audmode(client,mode_v4l1_to_v4l2(va->mode));
  1749. break;
  1750. }
  1751. case VIDIOCSCHAN:
  1752. {
  1753. struct video_channel *vc = arg;
  1754. msp3400_dbg("VIDIOCSCHAN (norm=%d)\n",vc->norm);
  1755. msp->norm = vc->norm;
  1756. msp_wake_thread(client);
  1757. break;
  1758. }
  1759. case VIDIOCSFREQ:
  1760. case VIDIOC_S_FREQUENCY:
  1761. {
  1762. /* new channel -- kick audio carrier scan */
  1763. msp3400_dbg("VIDIOCSFREQ\n");
  1764. msp_wake_thread(client);
  1765. break;
  1766. }
  1767. /* msp34xx specific */
  1768. case MSP_SET_MATRIX:
  1769. {
  1770. struct msp_matrix *mspm = arg;
  1771. msp3400_dbg("MSP_SET_MATRIX\n");
  1772. msp3400c_set_scart(client, mspm->input, mspm->output);
  1773. break;
  1774. }
  1775. /* --- v4l2 ioctls --- */
  1776. case VIDIOC_S_STD:
  1777. {
  1778. v4l2_std_id *id = arg;
  1779. /*FIXME: use V4L2 mode flags on msp3400 instead of V4L1*/
  1780. if (*id & V4L2_STD_PAL) {
  1781. msp->norm=VIDEO_MODE_PAL;
  1782. } else if (*id & V4L2_STD_SECAM) {
  1783. msp->norm=VIDEO_MODE_SECAM;
  1784. } else {
  1785. msp->norm=VIDEO_MODE_NTSC;
  1786. }
  1787. msp_wake_thread(client);
  1788. return 0;
  1789. }
  1790. case VIDIOC_ENUMINPUT:
  1791. {
  1792. struct v4l2_input *i = arg;
  1793. if (i->index != 0)
  1794. return -EINVAL;
  1795. i->type = V4L2_INPUT_TYPE_TUNER;
  1796. switch (i->index) {
  1797. case AUDIO_RADIO:
  1798. strcpy(i->name,"Radio");
  1799. break;
  1800. case AUDIO_EXTERN_1:
  1801. strcpy(i->name,"Extern 1");
  1802. break;
  1803. case AUDIO_EXTERN_2:
  1804. strcpy(i->name,"Extern 2");
  1805. break;
  1806. case AUDIO_TUNER:
  1807. strcpy(i->name,"Television");
  1808. break;
  1809. default:
  1810. return -EINVAL;
  1811. }
  1812. return 0;
  1813. }
  1814. case VIDIOC_G_AUDIO:
  1815. {
  1816. struct v4l2_audio *a = arg;
  1817. memset(a,0,sizeof(*a));
  1818. switch (a->index) {
  1819. case AUDIO_RADIO:
  1820. strcpy(a->name,"Radio");
  1821. break;
  1822. case AUDIO_EXTERN_1:
  1823. strcpy(a->name,"Extern 1");
  1824. break;
  1825. case AUDIO_EXTERN_2:
  1826. strcpy(a->name,"Extern 2");
  1827. break;
  1828. case AUDIO_TUNER:
  1829. strcpy(a->name,"Television");
  1830. break;
  1831. default:
  1832. return -EINVAL;
  1833. }
  1834. msp_any_detect_stereo(client);
  1835. if (msp->audmode == V4L2_TUNER_MODE_STEREO) {
  1836. a->capability=V4L2_AUDCAP_STEREO;
  1837. }
  1838. break;
  1839. }
  1840. case VIDIOC_S_AUDIO:
  1841. {
  1842. struct v4l2_audio *sarg = arg;
  1843. switch (sarg->index) {
  1844. case AUDIO_RADIO:
  1845. /* Hauppauge uses IN2 for the radio */
  1846. msp->mode = MSP_MODE_FM_RADIO;
  1847. scart = SCART_IN2;
  1848. break;
  1849. case AUDIO_EXTERN_1:
  1850. /* IN1 is often used for external input ... */
  1851. msp->mode = MSP_MODE_EXTERN;
  1852. scart = SCART_IN1;
  1853. break;
  1854. case AUDIO_EXTERN_2:
  1855. /* ... sometimes it is IN2 through ;) */
  1856. msp->mode = MSP_MODE_EXTERN;
  1857. scart = SCART_IN2;
  1858. break;
  1859. case AUDIO_TUNER:
  1860. msp->mode = -1;
  1861. break;
  1862. }
  1863. if (scart) {
  1864. msp->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1865. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1866. msp3400c_set_scart(client,scart,0);
  1867. msp3400c_write(client,I2C_MSP3400C_DFP,0x000d,0x1900);
  1868. }
  1869. if (sarg->capability==V4L2_AUDCAP_STEREO) {
  1870. msp->audmode = V4L2_TUNER_MODE_STEREO;
  1871. } else {
  1872. msp->audmode &= ~V4L2_TUNER_MODE_STEREO;
  1873. }
  1874. msp_any_set_audmode(client, msp->audmode);
  1875. msp_wake_thread(client);
  1876. break;
  1877. }
  1878. case VIDIOC_G_TUNER:
  1879. {
  1880. struct v4l2_tuner *vt = arg;
  1881. msp_any_detect_stereo(client);
  1882. vt->audmode = msp->audmode;
  1883. vt->rxsubchans = msp->rxsubchans;
  1884. vt->capability = V4L2_TUNER_CAP_STEREO |
  1885. V4L2_TUNER_CAP_LANG1|
  1886. V4L2_TUNER_CAP_LANG2;
  1887. break;
  1888. }
  1889. case VIDIOC_S_TUNER:
  1890. {
  1891. struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
  1892. /* only set audmode */
  1893. if (vt->audmode != -1 && vt->audmode != 0)
  1894. msp_any_set_audmode(client, vt->audmode);
  1895. break;
  1896. }
  1897. case VIDIOC_G_AUDOUT:
  1898. {
  1899. struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
  1900. int idx=a->index;
  1901. memset(a,0,sizeof(*a));
  1902. switch (idx) {
  1903. case 0:
  1904. strcpy(a->name,"Scart1 Out");
  1905. break;
  1906. case 1:
  1907. strcpy(a->name,"Scart2 Out");
  1908. break;
  1909. case 2:
  1910. strcpy(a->name,"I2S Out");
  1911. break;
  1912. default:
  1913. return -EINVAL;
  1914. }
  1915. break;
  1916. }
  1917. case VIDIOC_S_AUDOUT:
  1918. {
  1919. struct v4l2_audioout *a=(struct v4l2_audioout *)arg;
  1920. if (a->index<0||a->index>2)
  1921. return -EINVAL;
  1922. if (a->index==2) {
  1923. if (a->mode == V4L2_AUDMODE_32BITS)
  1924. msp->i2s_mode=1;
  1925. else
  1926. msp->i2s_mode=0;
  1927. }
  1928. msp3400_dbg("Setting audio out on msp34xx to input %i, mode %i\n",
  1929. a->index,msp->i2s_mode);
  1930. msp3400c_set_scart(client,msp->in_scart,a->index+1);
  1931. break;
  1932. }
  1933. default:
  1934. /* nothing */
  1935. break;
  1936. }
  1937. return 0;
  1938. }
  1939. static int msp_suspend(struct device * dev, pm_message_t state)
  1940. {
  1941. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  1942. msp3400_dbg("msp34xx: suspend\n");
  1943. msp3400c_reset(client);
  1944. return 0;
  1945. }
  1946. static int msp_resume(struct device * dev)
  1947. {
  1948. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  1949. msp3400_dbg("msp34xx: resume\n");
  1950. msp_wake_thread(client);
  1951. return 0;
  1952. }
  1953. /* ----------------------------------------------------------------------- */
  1954. static int __init msp3400_init_module(void)
  1955. {
  1956. return i2c_add_driver(&driver);
  1957. }
  1958. static void __exit msp3400_cleanup_module(void)
  1959. {
  1960. i2c_del_driver(&driver);
  1961. }
  1962. module_init(msp3400_init_module);
  1963. module_exit(msp3400_cleanup_module);
  1964. /*
  1965. * Overrides for Emacs so that we follow Linus's tabbing style.
  1966. * ---------------------------------------------------------------------------
  1967. * Local variables:
  1968. * c-basic-offset: 8
  1969. * End:
  1970. */