msp3400.c 60 KB

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