sb_ess.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. #undef FKS_LOGGING
  2. #undef FKS_TEST
  3. /*
  4. * tabs should be 4 spaces, in vi(m): set tabstop=4
  5. *
  6. * TODO: consistency speed calculations!!
  7. * cleanup!
  8. * ????: Did I break MIDI support?
  9. *
  10. * History:
  11. *
  12. * Rolf Fokkens (Dec 20 1998): ES188x recording level support on a per
  13. * fokkensr@vertis.nl input basis.
  14. * (Dec 24 1998): Recognition of ES1788, ES1887, ES1888,
  15. * ES1868, ES1869 and ES1878. Could be used for
  16. * specific handling in the future. All except
  17. * ES1887 and ES1888 and ES688 are handled like
  18. * ES1688.
  19. * (Dec 27 1998): RECLEV for all (?) ES1688+ chips. ES188x now
  20. * have the "Dec 20" support + RECLEV
  21. * (Jan 2 1999): Preparation for Full Duplex. This means
  22. * Audio 2 is now used for playback when dma16
  23. * is specified. The next step would be to use
  24. * Audio 1 and Audio 2 at the same time.
  25. * (Jan 9 1999): Put all ESS stuff into sb_ess.[ch], this
  26. * includes both the ESS stuff that has been in
  27. * sb_*[ch] before I touched it and the ESS support
  28. * I added later
  29. * (Jan 23 1999): Full Duplex seems to work. I wrote a small
  30. * test proggy which works OK. Haven't found
  31. * any applications to test it though. So why did
  32. * I bother to create it anyway?? :) Just for
  33. * fun.
  34. * (May 2 1999): I tried to be too smart by "introducing"
  35. * ess_calc_best_speed (). The idea was that two
  36. * dividers could be used to setup a samplerate,
  37. * ess_calc_best_speed () would choose the best.
  38. * This works for playback, but results in
  39. * recording problems for high samplerates. I
  40. * fixed this by removing ess_calc_best_speed ()
  41. * and just doing what the documentation says.
  42. * Andy Sloane (Jun 4 1999): Stole some code from ALSA to fix the playback
  43. * andy@guildsoftware.com speed on ES1869, ES1879, ES1887, and ES1888.
  44. * 1879's were previously ignored by this driver;
  45. * added (untested) support for those.
  46. * Cvetan Ivanov (Oct 27 1999): Fixed ess_dsp_init to call ess_set_dma_hw for
  47. * zezo@inet.bg _ALL_ ESS models, not only ES1887
  48. *
  49. * This files contains ESS chip specifics. It's based on the existing ESS
  50. * handling as it resided in sb_common.c, sb_mixer.c and sb_audio.c. This
  51. * file adds features like:
  52. * - Chip Identification (as shown in /proc/sound)
  53. * - RECLEV support for ES1688 and later
  54. * - 6 bits playback level support chips later than ES1688
  55. * - Recording level support on a per-device basis for ES1887
  56. * - Full-Duplex for ES1887
  57. *
  58. * Full duplex is enabled by specifying dma16. While the normal dma must
  59. * be one of 0, 1 or 3, dma16 can be one of 0, 1, 3 or 5. DMA 5 is a 16 bit
  60. * DMA channel, while the others are 8 bit..
  61. *
  62. * ESS detection isn't full proof (yet). If it fails an additional module
  63. * parameter esstype can be specified to be one of the following:
  64. * -1, 0, 688, 1688, 1868, 1869, 1788, 1887, 1888
  65. * -1 means: mimic 2.0 behaviour,
  66. * 0 means: auto detect.
  67. * others: explicitly specify chip
  68. * -1 is default, cause auto detect still doesn't work.
  69. */
  70. /*
  71. * About the documentation
  72. *
  73. * I don't know if the chips all are OK, but the documentation is buggy. 'cause
  74. * I don't have all the cips myself, there's a lot I cannot verify. I'll try to
  75. * keep track of my latest insights about his here. If you have additional info,
  76. * please enlighten me (fokkensr@vertis.nl)!
  77. *
  78. * I had the impression that ES1688 also has 6 bit master volume control. The
  79. * documentation about ES1888 (rev C, october '95) claims that ES1888 has
  80. * the following features ES1688 doesn't have:
  81. * - 6 bit master volume
  82. * - Full Duplex
  83. * So ES1688 apparently doesn't have 6 bit master volume control, but the
  84. * ES1688 does have RECLEV control. Makes me wonder: does ES688 have it too?
  85. * Without RECLEV ES688 won't be much fun I guess.
  86. *
  87. * From the ES1888 (rev C, october '95) documentation I got the impression
  88. * that registers 0x68 to 0x6e don't exist which means: no recording volume
  89. * controls. To my surprise the ES888 documentation (1/14/96) claims that
  90. * ES888 does have these record mixer registers, but that ES1888 doesn't have
  91. * 0x69 and 0x6b. So the rest should be there.
  92. *
  93. * I'm trying to get ES1887 Full Duplex. Audio 2 is playback only, while Audio 2
  94. * is both record and playback. I think I should use Audio 2 for all playback.
  95. *
  96. * The documentation is an adventure: it's close but not fully accurate. I
  97. * found out that after a reset some registers are *NOT* reset, though the
  98. * docs say the would be. Interesting ones are 0x7f, 0x7d and 0x7a. They are
  99. * related to the Audio 2 channel. I also was surprised about the consequences
  100. * of writing 0x00 to 0x7f (which should be done by reset): The ES1887 moves
  101. * into ES1888 mode. This means that it claims IRQ 11, which happens to be my
  102. * ISDN adapter. Needless to say it no longer worked. I now understand why
  103. * after rebooting 0x7f already was 0x05, the value of my choice: the BIOS
  104. * did it.
  105. *
  106. * Oh, and this is another trap: in ES1887 docs mixer register 0x70 is
  107. * described as if it's exactly the same as register 0xa1. This is *NOT* true.
  108. * The description of 0x70 in ES1869 docs is accurate however.
  109. * Well, the assumption about ES1869 was wrong: register 0x70 is very much
  110. * like register 0xa1, except that bit 7 is always 1, whatever you want
  111. * it to be.
  112. *
  113. * When using audio 2 mixer register 0x72 seems te be meaningless. Only 0xa2
  114. * has effect.
  115. *
  116. * Software reset not being able to reset all registers is great! Especially
  117. * the fact that register 0x78 isn't reset is great when you wanna change back
  118. * to single dma operation (simplex): audio 2 is still operational, and uses
  119. * the same dma as audio 1: your ess changes into a funny echo machine.
  120. *
  121. * Received the news that ES1688 is detected as a ES1788. Did some thinking:
  122. * the ES1887 detection scheme suggests in step 2 to try if bit 3 of register
  123. * 0x64 can be changed. This is inaccurate, first I inverted the * check: "If
  124. * can be modified, it's a 1688", which lead to a correct detection
  125. * of my ES1887. It resulted however in bad detection of 1688 (reported by mail)
  126. * and 1868 (if no PnP detection first): they result in a 1788 being detected.
  127. * I don't have docs on 1688, but I do have docs on 1868: The documentation is
  128. * probably inaccurate in the fact that I should check bit 2, not bit 3. This
  129. * is what I do now.
  130. */
  131. /*
  132. * About recognition of ESS chips
  133. *
  134. * The distinction of ES688, ES1688, ES1788, ES1887 and ES1888 is described in
  135. * a (preliminary ??) datasheet on ES1887. Its aim is to identify ES1887, but
  136. * during detection the text claims that "this chip may be ..." when a step
  137. * fails. This scheme is used to distinct between the above chips.
  138. * It appears however that some PnP chips like ES1868 are recognized as ES1788
  139. * by the ES1887 detection scheme. These PnP chips can be detected in another
  140. * way however: ES1868, ES1869 and ES1878 can be recognized (full proof I think)
  141. * by repeatedly reading mixer register 0x40. This is done by ess_identify in
  142. * sb_common.c.
  143. * This results in the following detection steps:
  144. * - distinct between ES688 and ES1688+ (as always done in this driver)
  145. * if ES688 we're ready
  146. * - try to detect ES1868, ES1869 or ES1878
  147. * if successful we're ready
  148. * - try to detect ES1888, ES1887 or ES1788
  149. * if successful we're ready
  150. * - Dunno. Must be 1688. Will do in general
  151. *
  152. * About RECLEV support:
  153. *
  154. * The existing ES1688 support didn't take care of the ES1688+ recording
  155. * levels very well. Whenever a device was selected (recmask) for recording
  156. * its recording level was loud, and it couldn't be changed. The fact that
  157. * internal register 0xb4 could take care of RECLEV, didn't work meaning until
  158. * its value was restored every time the chip was reset; this reset the
  159. * value of 0xb4 too. I guess that's what 4front also had (have?) trouble with.
  160. *
  161. * About ES1887 support:
  162. *
  163. * The ES1887 has separate registers to control the recording levels, for all
  164. * inputs. The ES1887 specific software makes these levels the same as their
  165. * corresponding playback levels, unless recmask says they aren't recorded. In
  166. * the latter case the recording volumes are 0.
  167. * Now recording levels of inputs can be controlled, by changing the playback
  168. * levels. Furthermore several devices can be recorded together (which is not
  169. * possible with the ES1688).
  170. * Besides the separate recording level control for each input, the common
  171. * recording level can also be controlled by RECLEV as described above.
  172. *
  173. * Not only ES1887 have this recording mixer. I know the following from the
  174. * documentation:
  175. * ES688 no
  176. * ES1688 no
  177. * ES1868 no
  178. * ES1869 yes
  179. * ES1878 no
  180. * ES1879 yes
  181. * ES1888 no/yes Contradicting documentation; most recent: yes
  182. * ES1946 yes This is a PCI chip; not handled by this driver
  183. */
  184. #include <linux/delay.h>
  185. #include <linux/interrupt.h>
  186. #include <linux/spinlock.h>
  187. #include "sound_config.h"
  188. #include "sb_mixer.h"
  189. #include "sb.h"
  190. #include "sb_ess.h"
  191. #define ESSTYPE_LIKE20 -1 /* Mimic 2.0 behaviour */
  192. #define ESSTYPE_DETECT 0 /* Mimic 2.0 behaviour */
  193. #define SUBMDL_ES1788 0x10 /* Subtype ES1788 for specific handling */
  194. #define SUBMDL_ES1868 0x11 /* Subtype ES1868 for specific handling */
  195. #define SUBMDL_ES1869 0x12 /* Subtype ES1869 for specific handling */
  196. #define SUBMDL_ES1878 0x13 /* Subtype ES1878 for specific handling */
  197. #define SUBMDL_ES1879 0x16 /* ES1879 was initially forgotten */
  198. #define SUBMDL_ES1887 0x14 /* Subtype ES1887 for specific handling */
  199. #define SUBMDL_ES1888 0x15 /* Subtype ES1888 for specific handling */
  200. #define SB_CAP_ES18XX_RATE 0x100
  201. #define ES1688_CLOCK1 795444 /* 128 - div */
  202. #define ES1688_CLOCK2 397722 /* 256 - div */
  203. #define ES18XX_CLOCK1 793800 /* 128 - div */
  204. #define ES18XX_CLOCK2 768000 /* 256 - div */
  205. #ifdef FKS_LOGGING
  206. static void ess_show_mixerregs (sb_devc *devc);
  207. #endif
  208. static int ess_read (sb_devc * devc, unsigned char reg);
  209. static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data);
  210. static void ess_chgmixer
  211. (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val);
  212. /****************************************************************************
  213. * *
  214. * ESS audio *
  215. * *
  216. ****************************************************************************/
  217. struct ess_command {short cmd; short data;};
  218. /*
  219. * Commands for initializing Audio 1 for input (record)
  220. */
  221. static struct ess_command ess_i08m[] = /* input 8 bit mono */
  222. { {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
  223. static struct ess_command ess_i16m[] = /* input 16 bit mono */
  224. { {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
  225. static struct ess_command ess_i08s[] = /* input 8 bit stereo */
  226. { {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
  227. static struct ess_command ess_i16s[] = /* input 16 bit stereo */
  228. { {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
  229. static struct ess_command *ess_inp_cmds[] =
  230. { ess_i08m, ess_i16m, ess_i08s, ess_i16s };
  231. /*
  232. * Commands for initializing Audio 1 for output (playback)
  233. */
  234. static struct ess_command ess_o08m[] = /* output 8 bit mono */
  235. { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
  236. static struct ess_command ess_o16m[] = /* output 16 bit mono */
  237. { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
  238. static struct ess_command ess_o08s[] = /* output 8 bit stereo */
  239. { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
  240. static struct ess_command ess_o16s[] = /* output 16 bit stereo */
  241. { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
  242. static struct ess_command *ess_out_cmds[] =
  243. { ess_o08m, ess_o16m, ess_o08s, ess_o16s };
  244. static void ess_exec_commands
  245. (sb_devc *devc, struct ess_command *cmdtab[])
  246. {
  247. struct ess_command *cmd;
  248. cmd = cmdtab [ ((devc->channels != 1) << 1) + (devc->bits != AFMT_U8) ];
  249. while (cmd->cmd != -1) {
  250. ess_write (devc, cmd->cmd, cmd->data);
  251. cmd++;
  252. }
  253. }
  254. static void ess_change
  255. (sb_devc *devc, unsigned int reg, unsigned int mask, unsigned int val)
  256. {
  257. int value;
  258. value = ess_read (devc, reg);
  259. value = (value & ~mask) | (val & mask);
  260. ess_write (devc, reg, value);
  261. }
  262. static void ess_set_output_parms
  263. (int dev, unsigned long buf, int nr_bytes, int intrflag)
  264. {
  265. sb_devc *devc = audio_devs[dev]->devc;
  266. if (devc->duplex) {
  267. devc->trg_buf_16 = buf;
  268. devc->trg_bytes_16 = nr_bytes;
  269. devc->trg_intrflag_16 = intrflag;
  270. devc->irq_mode_16 = IMODE_OUTPUT;
  271. } else {
  272. devc->trg_buf = buf;
  273. devc->trg_bytes = nr_bytes;
  274. devc->trg_intrflag = intrflag;
  275. devc->irq_mode = IMODE_OUTPUT;
  276. }
  277. }
  278. static void ess_set_input_parms
  279. (int dev, unsigned long buf, int count, int intrflag)
  280. {
  281. sb_devc *devc = audio_devs[dev]->devc;
  282. devc->trg_buf = buf;
  283. devc->trg_bytes = count;
  284. devc->trg_intrflag = intrflag;
  285. devc->irq_mode = IMODE_INPUT;
  286. }
  287. static int ess_calc_div (int clock, int revert, int *speedp, int *diffp)
  288. {
  289. int divider;
  290. int speed, diff;
  291. int retval;
  292. speed = *speedp;
  293. divider = (clock + speed / 2) / speed;
  294. retval = revert - divider;
  295. if (retval > revert - 1) {
  296. retval = revert - 1;
  297. divider = revert - retval;
  298. }
  299. /* This line is suggested. Must be wrong I think
  300. *speedp = (clock + divider / 2) / divider;
  301. So I chose the next one */
  302. *speedp = clock / divider;
  303. diff = speed - *speedp;
  304. if (diff < 0) diff =-diff;
  305. *diffp = diff;
  306. return retval;
  307. }
  308. static int ess_calc_best_speed
  309. (int clock1, int rev1, int clock2, int rev2, int *divp, int *speedp)
  310. {
  311. int speed1 = *speedp, speed2 = *speedp;
  312. int div1, div2;
  313. int diff1, diff2;
  314. int retval;
  315. div1 = ess_calc_div (clock1, rev1, &speed1, &diff1);
  316. div2 = ess_calc_div (clock2, rev2, &speed2, &diff2);
  317. if (diff1 < diff2) {
  318. *divp = div1;
  319. *speedp = speed1;
  320. retval = 1;
  321. } else {
  322. /* *divp = div2; */
  323. *divp = 0x80 | div2;
  324. *speedp = speed2;
  325. retval = 2;
  326. }
  327. return retval;
  328. }
  329. /*
  330. * Depending on the audiochannel ESS devices can
  331. * have different clock settings. These are made consistent for duplex
  332. * however.
  333. * callers of ess_speed only do an audionum suggestion, which means
  334. * input suggests 1, output suggests 2. This suggestion is only true
  335. * however when doing duplex.
  336. */
  337. static void ess_common_speed (sb_devc *devc, int *speedp, int *divp)
  338. {
  339. int diff = 0, div;
  340. if (devc->duplex) {
  341. /*
  342. * The 0x80 is important for the first audio channel
  343. */
  344. if (devc->submodel == SUBMDL_ES1888) {
  345. div = 0x80 | ess_calc_div (795500, 256, speedp, &diff);
  346. } else {
  347. div = 0x80 | ess_calc_div (795500, 128, speedp, &diff);
  348. }
  349. } else if(devc->caps & SB_CAP_ES18XX_RATE) {
  350. if (devc->submodel == SUBMDL_ES1888) {
  351. ess_calc_best_speed(397700, 128, 795500, 256,
  352. &div, speedp);
  353. } else {
  354. ess_calc_best_speed(ES18XX_CLOCK1, 128, ES18XX_CLOCK2, 256,
  355. &div, speedp);
  356. }
  357. } else {
  358. if (*speedp > 22000) {
  359. div = 0x80 | ess_calc_div (ES1688_CLOCK1, 256, speedp, &diff);
  360. } else {
  361. div = 0x00 | ess_calc_div (ES1688_CLOCK2, 128, speedp, &diff);
  362. }
  363. }
  364. *divp = div;
  365. }
  366. static void ess_speed (sb_devc *devc, int audionum)
  367. {
  368. int speed;
  369. int div, div2;
  370. ess_common_speed (devc, &(devc->speed), &div);
  371. #ifdef FKS_REG_LOGGING
  372. printk (KERN_INFO "FKS: ess_speed (%d) b speed = %d, div=%x\n", audionum, devc->speed, div);
  373. #endif
  374. /* Set filter roll-off to 90% of speed/2 */
  375. speed = (devc->speed * 9) / 20;
  376. div2 = 256 - 7160000 / (speed * 82);
  377. if (!devc->duplex) audionum = 1;
  378. if (audionum == 1) {
  379. /* Change behaviour of register A1 *
  380. sb_chg_mixer(devc, 0x71, 0x20, 0x20)
  381. * For ES1869 only??? */
  382. ess_write (devc, 0xa1, div);
  383. ess_write (devc, 0xa2, div2);
  384. } else {
  385. ess_setmixer (devc, 0x70, div);
  386. /*
  387. * FKS: fascinating: 0x72 doesn't seem to work.
  388. */
  389. ess_write (devc, 0xa2, div2);
  390. ess_setmixer (devc, 0x72, div2);
  391. }
  392. }
  393. static int ess_audio_prepare_for_input(int dev, int bsize, int bcount)
  394. {
  395. sb_devc *devc = audio_devs[dev]->devc;
  396. ess_speed(devc, 1);
  397. sb_dsp_command(devc, DSP_CMD_SPKOFF);
  398. ess_write (devc, 0xb8, 0x0e); /* Auto init DMA mode */
  399. ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
  400. ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/DMA request) */
  401. ess_exec_commands (devc, ess_inp_cmds);
  402. ess_change (devc, 0xb1, 0xf0, 0x50);
  403. ess_change (devc, 0xb2, 0xf0, 0x50);
  404. devc->trigger_bits = 0;
  405. return 0;
  406. }
  407. static int ess_audio_prepare_for_output_audio1 (int dev, int bsize, int bcount)
  408. {
  409. sb_devc *devc = audio_devs[dev]->devc;
  410. sb_dsp_reset(devc);
  411. ess_speed(devc, 1);
  412. ess_write (devc, 0xb8, 4); /* Auto init DMA mode */
  413. ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
  414. ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/request) */
  415. ess_exec_commands (devc, ess_out_cmds);
  416. ess_change (devc, 0xb1, 0xf0, 0x50); /* Enable DMA */
  417. ess_change (devc, 0xb2, 0xf0, 0x50); /* Enable IRQ */
  418. sb_dsp_command(devc, DSP_CMD_SPKON); /* There be sound! */
  419. devc->trigger_bits = 0;
  420. return 0;
  421. }
  422. static int ess_audio_prepare_for_output_audio2 (int dev, int bsize, int bcount)
  423. {
  424. sb_devc *devc = audio_devs[dev]->devc;
  425. unsigned char bits;
  426. /* FKS: qqq
  427. sb_dsp_reset(devc);
  428. */
  429. /*
  430. * Auto-Initialize:
  431. * DMA mode + demand mode (8 bytes/request, yes I want it all!)
  432. * But leave 16-bit DMA bit untouched!
  433. */
  434. ess_chgmixer (devc, 0x78, 0xd0, 0xd0);
  435. ess_speed(devc, 2);
  436. /* bits 4:3 on ES1887 represent recording source. Keep them! */
  437. bits = ess_getmixer (devc, 0x7a) & 0x18;
  438. /* Set stereo/mono */
  439. if (devc->channels != 1) bits |= 0x02;
  440. /* Init DACs; UNSIGNED mode for 8 bit; SIGNED mode for 16 bit */
  441. if (devc->bits != AFMT_U8) bits |= 0x05; /* 16 bit */
  442. /* Enable DMA, IRQ will be shared (hopefully)*/
  443. bits |= 0x60;
  444. ess_setmixer (devc, 0x7a, bits);
  445. ess_mixer_reload (devc, SOUND_MIXER_PCM); /* There be sound! */
  446. devc->trigger_bits = 0;
  447. return 0;
  448. }
  449. static int ess_audio_prepare_for_output(int dev, int bsize, int bcount)
  450. {
  451. sb_devc *devc = audio_devs[dev]->devc;
  452. #ifdef FKS_REG_LOGGING
  453. printk(KERN_INFO "ess_audio_prepare_for_output: dma_out=%d,dma_in=%d\n"
  454. , audio_devs[dev]->dmap_out->dma, audio_devs[dev]->dmap_in->dma);
  455. #endif
  456. if (devc->duplex) {
  457. return ess_audio_prepare_for_output_audio2 (dev, bsize, bcount);
  458. } else {
  459. return ess_audio_prepare_for_output_audio1 (dev, bsize, bcount);
  460. }
  461. }
  462. static void ess_audio_halt_xfer(int dev)
  463. {
  464. unsigned long flags;
  465. sb_devc *devc = audio_devs[dev]->devc;
  466. spin_lock_irqsave(&devc->lock, flags);
  467. sb_dsp_reset(devc);
  468. spin_unlock_irqrestore(&devc->lock, flags);
  469. /*
  470. * Audio 2 may still be operational! Creates awful sounds!
  471. */
  472. if (devc->duplex) ess_chgmixer(devc, 0x78, 0x03, 0x00);
  473. }
  474. static void ess_audio_start_input
  475. (int dev, unsigned long buf, int nr_bytes, int intrflag)
  476. {
  477. int count = nr_bytes;
  478. sb_devc *devc = audio_devs[dev]->devc;
  479. short c = -nr_bytes;
  480. /*
  481. * Start a DMA input to the buffer pointed by dmaqtail
  482. */
  483. if (audio_devs[dev]->dmap_in->dma > 3) count >>= 1;
  484. count--;
  485. devc->irq_mode = IMODE_INPUT;
  486. ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
  487. ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
  488. ess_change (devc, 0xb8, 0x0f, 0x0f); /* Go */
  489. devc->intr_active = 1;
  490. }
  491. static void ess_audio_output_block_audio1
  492. (int dev, unsigned long buf, int nr_bytes, int intrflag)
  493. {
  494. int count = nr_bytes;
  495. sb_devc *devc = audio_devs[dev]->devc;
  496. short c = -nr_bytes;
  497. if (audio_devs[dev]->dmap_out->dma > 3)
  498. count >>= 1;
  499. count--;
  500. devc->irq_mode = IMODE_OUTPUT;
  501. ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
  502. ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
  503. ess_change (devc, 0xb8, 0x05, 0x05); /* Go */
  504. devc->intr_active = 1;
  505. }
  506. static void ess_audio_output_block_audio2
  507. (int dev, unsigned long buf, int nr_bytes, int intrflag)
  508. {
  509. int count = nr_bytes;
  510. sb_devc *devc = audio_devs[dev]->devc;
  511. short c = -nr_bytes;
  512. if (audio_devs[dev]->dmap_out->dma > 3) count >>= 1;
  513. count--;
  514. ess_setmixer (devc, 0x74, (unsigned char) ((unsigned short) c & 0xff));
  515. ess_setmixer (devc, 0x76, (unsigned char) (((unsigned short) c >> 8) & 0xff));
  516. ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */
  517. devc->irq_mode_16 = IMODE_OUTPUT;
  518. devc->intr_active_16 = 1;
  519. }
  520. static void ess_audio_output_block
  521. (int dev, unsigned long buf, int nr_bytes, int intrflag)
  522. {
  523. sb_devc *devc = audio_devs[dev]->devc;
  524. if (devc->duplex) {
  525. ess_audio_output_block_audio2 (dev, buf, nr_bytes, intrflag);
  526. } else {
  527. ess_audio_output_block_audio1 (dev, buf, nr_bytes, intrflag);
  528. }
  529. }
  530. /*
  531. * FKS: the if-statements for both bits and bits_16 are quite alike.
  532. * Combine this...
  533. */
  534. static void ess_audio_trigger(int dev, int bits)
  535. {
  536. sb_devc *devc = audio_devs[dev]->devc;
  537. int bits_16 = bits & devc->irq_mode_16;
  538. bits &= devc->irq_mode;
  539. if (!bits && !bits_16) {
  540. /* FKS oh oh.... wrong?? for dma 16? */
  541. sb_dsp_command(devc, 0xd0); /* Halt DMA */
  542. }
  543. if (bits) {
  544. switch (devc->irq_mode)
  545. {
  546. case IMODE_INPUT:
  547. ess_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
  548. devc->trg_intrflag);
  549. break;
  550. case IMODE_OUTPUT:
  551. ess_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
  552. devc->trg_intrflag);
  553. break;
  554. }
  555. }
  556. if (bits_16) {
  557. switch (devc->irq_mode_16) {
  558. case IMODE_INPUT:
  559. ess_audio_start_input(dev, devc->trg_buf_16, devc->trg_bytes_16,
  560. devc->trg_intrflag_16);
  561. break;
  562. case IMODE_OUTPUT:
  563. ess_audio_output_block(dev, devc->trg_buf_16, devc->trg_bytes_16,
  564. devc->trg_intrflag_16);
  565. break;
  566. }
  567. }
  568. devc->trigger_bits = bits | bits_16;
  569. }
  570. static int ess_audio_set_speed(int dev, int speed)
  571. {
  572. sb_devc *devc = audio_devs[dev]->devc;
  573. int minspeed, maxspeed, dummydiv;
  574. if (speed > 0) {
  575. minspeed = (devc->duplex ? 6215 : 5000 );
  576. maxspeed = (devc->duplex ? 44100 : 48000);
  577. if (speed < minspeed) speed = minspeed;
  578. if (speed > maxspeed) speed = maxspeed;
  579. ess_common_speed (devc, &speed, &dummydiv);
  580. devc->speed = speed;
  581. }
  582. return devc->speed;
  583. }
  584. /*
  585. * FKS: This is a one-on-one copy of sb1_audio_set_bits
  586. */
  587. static unsigned int ess_audio_set_bits(int dev, unsigned int bits)
  588. {
  589. sb_devc *devc = audio_devs[dev]->devc;
  590. if (bits != 0) {
  591. if (bits == AFMT_U8 || bits == AFMT_S16_LE) {
  592. devc->bits = bits;
  593. } else {
  594. devc->bits = AFMT_U8;
  595. }
  596. }
  597. return devc->bits;
  598. }
  599. /*
  600. * FKS: This is a one-on-one copy of sbpro_audio_set_channels
  601. * (*) Modified it!!
  602. */
  603. static short ess_audio_set_channels(int dev, short channels)
  604. {
  605. sb_devc *devc = audio_devs[dev]->devc;
  606. if (channels == 1 || channels == 2) devc->channels = channels;
  607. return devc->channels;
  608. }
  609. static struct audio_driver ess_audio_driver = /* ESS ES688/1688 */
  610. {
  611. .owner = THIS_MODULE,
  612. .open = sb_audio_open,
  613. .close = sb_audio_close,
  614. .output_block = ess_set_output_parms,
  615. .start_input = ess_set_input_parms,
  616. .prepare_for_input = ess_audio_prepare_for_input,
  617. .prepare_for_output = ess_audio_prepare_for_output,
  618. .halt_io = ess_audio_halt_xfer,
  619. .trigger = ess_audio_trigger,
  620. .set_speed = ess_audio_set_speed,
  621. .set_bits = ess_audio_set_bits,
  622. .set_channels = ess_audio_set_channels
  623. };
  624. /*
  625. * ess_audio_init must be called from sb_audio_init
  626. */
  627. struct audio_driver *ess_audio_init
  628. (sb_devc *devc, int *audio_flags, int *format_mask)
  629. {
  630. *audio_flags = DMA_AUTOMODE;
  631. *format_mask |= AFMT_S16_LE;
  632. if (devc->duplex) {
  633. int tmp_dma;
  634. /*
  635. * sb_audio_init thinks dma8 is for playback and
  636. * dma16 is for record. Not now! So swap them.
  637. */
  638. tmp_dma = devc->dma16;
  639. devc->dma16 = devc->dma8;
  640. devc->dma8 = tmp_dma;
  641. *audio_flags |= DMA_DUPLEX;
  642. }
  643. return &ess_audio_driver;
  644. }
  645. /****************************************************************************
  646. * *
  647. * ESS common *
  648. * *
  649. ****************************************************************************/
  650. static void ess_handle_channel
  651. (char *channel, int dev, int intr_active, unsigned char flag, int irq_mode)
  652. {
  653. if (!intr_active || !flag) return;
  654. #ifdef FKS_REG_LOGGING
  655. printk(KERN_INFO "FKS: ess_handle_channel %s irq_mode=%d\n", channel, irq_mode);
  656. #endif
  657. switch (irq_mode) {
  658. case IMODE_OUTPUT:
  659. DMAbuf_outputintr (dev, 1);
  660. break;
  661. case IMODE_INPUT:
  662. DMAbuf_inputintr (dev);
  663. break;
  664. case IMODE_INIT:
  665. break;
  666. default:;
  667. /* printk(KERN_WARNING "ESS: Unexpected interrupt\n"); */
  668. }
  669. }
  670. /*
  671. * FKS: TODO!!! Finish this!
  672. *
  673. * I think midi stuff uses uart401, without interrupts.
  674. * So IMODE_MIDI isn't a value for devc->irq_mode.
  675. */
  676. void ess_intr (sb_devc *devc)
  677. {
  678. int status;
  679. unsigned char src;
  680. if (devc->submodel == SUBMDL_ES1887) {
  681. src = ess_getmixer (devc, 0x7f) >> 4;
  682. } else {
  683. src = 0xff;
  684. }
  685. #ifdef FKS_REG_LOGGING
  686. printk(KERN_INFO "FKS: sbintr src=%x\n",(int)src);
  687. #endif
  688. ess_handle_channel
  689. ( "Audio 1"
  690. , devc->dev, devc->intr_active , src & 0x01, devc->irq_mode );
  691. ess_handle_channel
  692. ( "Audio 2"
  693. , devc->dev, devc->intr_active_16, src & 0x02, devc->irq_mode_16);
  694. /*
  695. * Acknowledge interrupts
  696. */
  697. if (devc->submodel == SUBMDL_ES1887 && (src & 0x02)) {
  698. ess_chgmixer (devc, 0x7a, 0x80, 0x00);
  699. }
  700. if (src & 0x01) {
  701. status = inb(DSP_DATA_AVAIL);
  702. }
  703. }
  704. static void ess_extended (sb_devc * devc)
  705. {
  706. /* Enable extended mode */
  707. sb_dsp_command(devc, 0xc6);
  708. }
  709. static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data)
  710. {
  711. #ifdef FKS_REG_LOGGING
  712. printk(KERN_INFO "FKS: write reg %x: %x\n", reg, data);
  713. #endif
  714. /* Write a byte to an extended mode register of ES1688 */
  715. if (!sb_dsp_command(devc, reg))
  716. return 0;
  717. return sb_dsp_command(devc, data);
  718. }
  719. static int ess_read (sb_devc * devc, unsigned char reg)
  720. {
  721. /* Read a byte from an extended mode register of ES1688 */
  722. /* Read register command */
  723. if (!sb_dsp_command(devc, 0xc0)) return -1;
  724. if (!sb_dsp_command(devc, reg )) return -1;
  725. return sb_dsp_get_byte(devc);
  726. }
  727. int ess_dsp_reset(sb_devc * devc)
  728. {
  729. int loopc;
  730. #ifdef FKS_REG_LOGGING
  731. printk(KERN_INFO "FKS: ess_dsp_reset 1\n");
  732. ess_show_mixerregs (devc);
  733. #endif
  734. outb(3, DSP_RESET); /* Reset FIFO too */
  735. udelay(10);
  736. outb(0, DSP_RESET);
  737. udelay(30);
  738. for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
  739. if (inb(DSP_READ) != 0xAA) {
  740. DDB(printk("sb: No response to RESET\n"));
  741. return 0; /* Sorry */
  742. }
  743. ess_extended (devc);
  744. #ifdef FKS_LOGGING
  745. printk(KERN_INFO "FKS: dsp_reset 2\n");
  746. ess_show_mixerregs (devc);
  747. #endif
  748. return 1;
  749. }
  750. static int ess_irq_bits (int irq)
  751. {
  752. switch (irq) {
  753. case 2:
  754. case 9:
  755. return 0;
  756. case 5:
  757. return 1;
  758. case 7:
  759. return 2;
  760. case 10:
  761. return 3;
  762. default:
  763. printk(KERN_ERR "ESS1688: Invalid IRQ %d\n", irq);
  764. return -1;
  765. }
  766. }
  767. /*
  768. * Set IRQ configuration register for all ESS models
  769. */
  770. static int ess_common_set_irq_hw (sb_devc * devc)
  771. {
  772. int irq_bits;
  773. if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return 0;
  774. if (!ess_write (devc, 0xb1, 0x50 | (irq_bits << 2))) {
  775. printk(KERN_ERR "ES1688: Failed to write to IRQ config register\n");
  776. return 0;
  777. }
  778. return 1;
  779. }
  780. /*
  781. * I wanna use modern ES1887 mixer irq handling. Funny is the
  782. * fact that my BIOS wants the same. But suppose someone's BIOS
  783. * doesn't do this!
  784. * This is independent of duplex. If there's a 1887 this will
  785. * prevent it from going into 1888 mode.
  786. */
  787. static void ess_es1887_set_irq_hw (sb_devc * devc)
  788. {
  789. int irq_bits;
  790. if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return;
  791. ess_chgmixer (devc, 0x7f, 0x0f, 0x01 | ((irq_bits + 1) << 1));
  792. }
  793. static int ess_set_irq_hw (sb_devc * devc)
  794. {
  795. if (devc->submodel == SUBMDL_ES1887) ess_es1887_set_irq_hw (devc);
  796. return ess_common_set_irq_hw (devc);
  797. }
  798. #ifdef FKS_TEST
  799. /*
  800. * FKS_test:
  801. * for ES1887: 00, 18, non wr bits: 0001 1000
  802. * for ES1868: 00, b8, non wr bits: 1011 1000
  803. * for ES1888: 00, f8, non wr bits: 1111 1000
  804. * for ES1688: 00, f8, non wr bits: 1111 1000
  805. * + ES968
  806. */
  807. static void FKS_test (sb_devc * devc)
  808. {
  809. int val1, val2;
  810. val1 = ess_getmixer (devc, 0x64);
  811. ess_setmixer (devc, 0x64, ~val1);
  812. val2 = ess_getmixer (devc, 0x64) ^ ~val1;
  813. ess_setmixer (devc, 0x64, val1);
  814. val1 ^= ess_getmixer (devc, 0x64);
  815. printk (KERN_INFO "FKS: FKS_test %02x, %02x\n", (val1 & 0x0ff), (val2 & 0x0ff));
  816. };
  817. #endif
  818. static unsigned int ess_identify (sb_devc * devc)
  819. {
  820. unsigned int val;
  821. unsigned long flags;
  822. spin_lock_irqsave(&devc->lock, flags);
  823. outb(((unsigned char) (0x40 & 0xff)), MIXER_ADDR);
  824. udelay(20);
  825. val = inb(MIXER_DATA) << 8;
  826. udelay(20);
  827. val |= inb(MIXER_DATA);
  828. udelay(20);
  829. spin_unlock_irqrestore(&devc->lock, flags);
  830. return val;
  831. }
  832. /*
  833. * ESS technology describes a detection scheme in their docs. It involves
  834. * fiddling with the bits in certain mixer registers. ess_probe is supposed
  835. * to help.
  836. *
  837. * FKS: tracing shows ess_probe writes wrong value to 0x64. Bit 3 reads 1, but
  838. * should be written 0 only. Check this.
  839. */
  840. static int ess_probe (sb_devc * devc, int reg, int xorval)
  841. {
  842. int val1, val2, val3;
  843. val1 = ess_getmixer (devc, reg);
  844. val2 = val1 ^ xorval;
  845. ess_setmixer (devc, reg, val2);
  846. val3 = ess_getmixer (devc, reg);
  847. ess_setmixer (devc, reg, val1);
  848. return (val2 == val3);
  849. }
  850. int ess_init(sb_devc * devc, struct address_info *hw_config)
  851. {
  852. unsigned char cfg;
  853. int ess_major = 0, ess_minor = 0;
  854. int i;
  855. static char name[100], modelname[10];
  856. /*
  857. * Try to detect ESS chips.
  858. */
  859. sb_dsp_command(devc, 0xe7); /* Return identification */
  860. for (i = 1000; i; i--) {
  861. if (inb(DSP_DATA_AVAIL) & 0x80) {
  862. if (ess_major == 0) {
  863. ess_major = inb(DSP_READ);
  864. } else {
  865. ess_minor = inb(DSP_READ);
  866. break;
  867. }
  868. }
  869. }
  870. if (ess_major == 0) return 0;
  871. if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80) {
  872. sprintf(name, "ESS ES488 AudioDrive (rev %d)",
  873. ess_minor & 0x0f);
  874. hw_config->name = name;
  875. devc->model = MDL_SBPRO;
  876. return 1;
  877. }
  878. /*
  879. * This the detection heuristic of ESS technology, though somewhat
  880. * changed to actually make it work.
  881. * This results in the following detection steps:
  882. * - distinct between ES688 and ES1688+ (as always done in this driver)
  883. * if ES688 we're ready
  884. * - try to detect ES1868, ES1869 or ES1878 (ess_identify)
  885. * if successful we're ready
  886. * - try to detect ES1888, ES1887 or ES1788 (aim: detect ES1887)
  887. * if successful we're ready
  888. * - Dunno. Must be 1688. Will do in general
  889. *
  890. * This is the most BETA part of the software: Will the detection
  891. * always work?
  892. */
  893. devc->model = MDL_ESS;
  894. devc->submodel = ess_minor & 0x0f;
  895. if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80) {
  896. char *chip = NULL;
  897. int submodel = -1;
  898. switch (devc->sbmo.esstype) {
  899. case ESSTYPE_DETECT:
  900. case ESSTYPE_LIKE20:
  901. break;
  902. case 688:
  903. submodel = 0x00;
  904. break;
  905. case 1688:
  906. submodel = 0x08;
  907. break;
  908. case 1868:
  909. submodel = SUBMDL_ES1868;
  910. break;
  911. case 1869:
  912. submodel = SUBMDL_ES1869;
  913. break;
  914. case 1788:
  915. submodel = SUBMDL_ES1788;
  916. break;
  917. case 1878:
  918. submodel = SUBMDL_ES1878;
  919. break;
  920. case 1879:
  921. submodel = SUBMDL_ES1879;
  922. break;
  923. case 1887:
  924. submodel = SUBMDL_ES1887;
  925. break;
  926. case 1888:
  927. submodel = SUBMDL_ES1888;
  928. break;
  929. default:
  930. printk (KERN_ERR "Invalid esstype=%d specified\n", devc->sbmo.esstype);
  931. return 0;
  932. }
  933. if (submodel != -1) {
  934. devc->submodel = submodel;
  935. sprintf (modelname, "ES%d", devc->sbmo.esstype);
  936. chip = modelname;
  937. }
  938. if (chip == NULL && (ess_minor & 0x0f) < 8) {
  939. chip = "ES688";
  940. }
  941. #ifdef FKS_TEST
  942. FKS_test (devc);
  943. #endif
  944. /*
  945. * If Nothing detected yet, and we want 2.0 behaviour...
  946. * Then let's assume it's ES1688.
  947. */
  948. if (chip == NULL && devc->sbmo.esstype == ESSTYPE_LIKE20) {
  949. chip = "ES1688";
  950. }
  951. if (chip == NULL) {
  952. int type;
  953. type = ess_identify (devc);
  954. switch (type) {
  955. case 0x1868:
  956. chip = "ES1868";
  957. devc->submodel = SUBMDL_ES1868;
  958. break;
  959. case 0x1869:
  960. chip = "ES1869";
  961. devc->submodel = SUBMDL_ES1869;
  962. break;
  963. case 0x1878:
  964. chip = "ES1878";
  965. devc->submodel = SUBMDL_ES1878;
  966. break;
  967. case 0x1879:
  968. chip = "ES1879";
  969. devc->submodel = SUBMDL_ES1879;
  970. break;
  971. default:
  972. if ((type & 0x00ff) != ((type >> 8) & 0x00ff)) {
  973. printk ("ess_init: Unrecognized %04x\n", type);
  974. }
  975. }
  976. }
  977. #if 0
  978. /*
  979. * this one failed:
  980. * the probing of bit 4 is another thought: from ES1788 and up, all
  981. * chips seem to have hardware volume control. Bit 4 is readonly to
  982. * check if a hardware volume interrupt has fired.
  983. * Cause ES688/ES1688 don't have this feature, bit 4 might be writeable
  984. * for these chips.
  985. */
  986. if (chip == NULL && !ess_probe(devc, 0x64, (1 << 4))) {
  987. #endif
  988. /*
  989. * the probing of bit 2 is my idea. The ES1887 docs want me to probe
  990. * bit 3. This results in ES1688 being detected as ES1788.
  991. * Bit 2 is for "Enable HWV IRQE", but as ES(1)688 chips don't have
  992. * HardWare Volume, I think they don't have this IRQE.
  993. */
  994. if (chip == NULL && ess_probe(devc, 0x64, (1 << 2))) {
  995. if (ess_probe (devc, 0x70, 0x7f)) {
  996. if (ess_probe (devc, 0x64, (1 << 5))) {
  997. chip = "ES1887";
  998. devc->submodel = SUBMDL_ES1887;
  999. } else {
  1000. chip = "ES1888";
  1001. devc->submodel = SUBMDL_ES1888;
  1002. }
  1003. } else {
  1004. chip = "ES1788";
  1005. devc->submodel = SUBMDL_ES1788;
  1006. }
  1007. }
  1008. if (chip == NULL) {
  1009. chip = "ES1688";
  1010. }
  1011. printk(KERN_INFO "ESS chip %s %s%s\n", chip,
  1012. (devc->sbmo.esstype == ESSTYPE_DETECT ||
  1013. devc->sbmo.esstype == ESSTYPE_LIKE20) ?
  1014. "detected" : "specified",
  1015. devc->sbmo.esstype == ESSTYPE_LIKE20 ?
  1016. " (kernel 2.0 compatible)" : "");
  1017. sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
  1018. } else {
  1019. strcpy(name, "Jazz16");
  1020. }
  1021. /* AAS: info stolen from ALSA: these boards have different clocks */
  1022. switch(devc->submodel) {
  1023. /* APPARENTLY NOT 1869 AND 1887
  1024. case SUBMDL_ES1869:
  1025. case SUBMDL_ES1887:
  1026. */
  1027. case SUBMDL_ES1888:
  1028. devc->caps |= SB_CAP_ES18XX_RATE;
  1029. break;
  1030. }
  1031. hw_config->name = name;
  1032. /* FKS: sb_dsp_reset to enable extended mode???? */
  1033. sb_dsp_reset(devc); /* Turn on extended mode */
  1034. /*
  1035. * Enable joystick and OPL3
  1036. */
  1037. cfg = ess_getmixer (devc, 0x40);
  1038. ess_setmixer (devc, 0x40, cfg | 0x03);
  1039. if (devc->submodel >= 8) { /* ES1688 */
  1040. devc->caps |= SB_NO_MIDI; /* ES1688 uses MPU401 MIDI mode */
  1041. }
  1042. sb_dsp_reset (devc);
  1043. /*
  1044. * This is important! If it's not done, the IRQ probe in sb_dsp_init
  1045. * may fail.
  1046. */
  1047. return ess_set_irq_hw (devc);
  1048. }
  1049. static int ess_set_dma_hw(sb_devc * devc)
  1050. {
  1051. unsigned char cfg, dma_bits = 0, dma16_bits;
  1052. int dma;
  1053. #ifdef FKS_LOGGING
  1054. printk(KERN_INFO "ess_set_dma_hw: dma8=%d,dma16=%d,dup=%d\n"
  1055. , devc->dma8, devc->dma16, devc->duplex);
  1056. #endif
  1057. /*
  1058. * FKS: It seems as if this duplex flag isn't set yet. Check it.
  1059. */
  1060. dma = devc->dma8;
  1061. if (dma > 3 || dma < 0 || dma == 2) {
  1062. dma_bits = 0;
  1063. printk(KERN_ERR "ESS1688: Invalid DMA8 %d\n", dma);
  1064. return 0;
  1065. } else {
  1066. /* Extended mode DMA enable */
  1067. cfg = 0x50;
  1068. if (dma == 3) {
  1069. dma_bits = 3;
  1070. } else {
  1071. dma_bits = dma + 1;
  1072. }
  1073. }
  1074. if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2))) {
  1075. printk(KERN_ERR "ESS1688: Failed to write to DMA config register\n");
  1076. return 0;
  1077. }
  1078. if (devc->duplex) {
  1079. dma = devc->dma16;
  1080. dma16_bits = 0;
  1081. if (dma >= 0) {
  1082. switch (dma) {
  1083. case 0:
  1084. dma_bits = 0x04;
  1085. break;
  1086. case 1:
  1087. dma_bits = 0x05;
  1088. break;
  1089. case 3:
  1090. dma_bits = 0x06;
  1091. break;
  1092. case 5:
  1093. dma_bits = 0x07;
  1094. dma16_bits = 0x20;
  1095. break;
  1096. default:
  1097. printk(KERN_ERR "ESS1887: Invalid DMA16 %d\n", dma);
  1098. return 0;
  1099. }
  1100. ess_chgmixer (devc, 0x78, 0x20, dma16_bits);
  1101. ess_chgmixer (devc, 0x7d, 0x07, dma_bits);
  1102. }
  1103. }
  1104. return 1;
  1105. }
  1106. /*
  1107. * This one is called from sb_dsp_init.
  1108. *
  1109. * Return values:
  1110. * 0: Failed
  1111. * 1: Succeeded or doesn't apply (not SUBMDL_ES1887)
  1112. */
  1113. int ess_dsp_init (sb_devc *devc, struct address_info *hw_config)
  1114. {
  1115. /*
  1116. * Caller also checks this, but anyway
  1117. */
  1118. if (devc->model != MDL_ESS) {
  1119. printk (KERN_INFO "ess_dsp_init for non ESS chip\n");
  1120. return 1;
  1121. }
  1122. /*
  1123. * This for ES1887 to run Full Duplex. Actually ES1888
  1124. * is allowed to do so too. I have no idea yet if this
  1125. * will work for ES1888 however.
  1126. *
  1127. * For SB16 having both dma8 and dma16 means enable
  1128. * Full Duplex. Let's try this for ES1887 too
  1129. *
  1130. */
  1131. if (devc->submodel == SUBMDL_ES1887) {
  1132. if (hw_config->dma2 != -1) {
  1133. devc->dma16 = hw_config->dma2;
  1134. }
  1135. /*
  1136. * devc->duplex initialization is put here, cause
  1137. * ess_set_dma_hw needs it.
  1138. */
  1139. if (devc->dma8 != devc->dma16 && devc->dma16 != -1) {
  1140. devc->duplex = 1;
  1141. }
  1142. }
  1143. if (!ess_set_dma_hw (devc)) {
  1144. free_irq(devc->irq, devc);
  1145. return 0;
  1146. }
  1147. return 1;
  1148. }
  1149. /****************************************************************************
  1150. * *
  1151. * ESS mixer *
  1152. * *
  1153. ****************************************************************************/
  1154. #define ES688_RECORDING_DEVICES \
  1155. ( SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD )
  1156. #define ES688_MIXER_DEVICES \
  1157. ( SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE \
  1158. | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME \
  1159. | SOUND_MASK_LINE2 | SOUND_MASK_SPEAKER )
  1160. #define ES1688_RECORDING_DEVICES \
  1161. ( ES688_RECORDING_DEVICES )
  1162. #define ES1688_MIXER_DEVICES \
  1163. ( ES688_MIXER_DEVICES | SOUND_MASK_RECLEV )
  1164. #define ES1887_RECORDING_DEVICES \
  1165. ( ES1688_RECORDING_DEVICES | SOUND_MASK_LINE2 | SOUND_MASK_SYNTH)
  1166. #define ES1887_MIXER_DEVICES \
  1167. ( ES1688_MIXER_DEVICES )
  1168. /*
  1169. * Mixer registers of ES1887
  1170. *
  1171. * These registers specifically take care of recording levels. To make the
  1172. * mapping from playback devices to recording devices every recording
  1173. * devices = playback device + ES_REC_MIXER_RECDIFF
  1174. */
  1175. #define ES_REC_MIXER_RECBASE (SOUND_MIXER_LINE3 + 1)
  1176. #define ES_REC_MIXER_RECDIFF (ES_REC_MIXER_RECBASE - SOUND_MIXER_SYNTH)
  1177. #define ES_REC_MIXER_RECSYNTH (SOUND_MIXER_SYNTH + ES_REC_MIXER_RECDIFF)
  1178. #define ES_REC_MIXER_RECPCM (SOUND_MIXER_PCM + ES_REC_MIXER_RECDIFF)
  1179. #define ES_REC_MIXER_RECSPEAKER (SOUND_MIXER_SPEAKER + ES_REC_MIXER_RECDIFF)
  1180. #define ES_REC_MIXER_RECLINE (SOUND_MIXER_LINE + ES_REC_MIXER_RECDIFF)
  1181. #define ES_REC_MIXER_RECMIC (SOUND_MIXER_MIC + ES_REC_MIXER_RECDIFF)
  1182. #define ES_REC_MIXER_RECCD (SOUND_MIXER_CD + ES_REC_MIXER_RECDIFF)
  1183. #define ES_REC_MIXER_RECIMIX (SOUND_MIXER_IMIX + ES_REC_MIXER_RECDIFF)
  1184. #define ES_REC_MIXER_RECALTPCM (SOUND_MIXER_ALTPCM + ES_REC_MIXER_RECDIFF)
  1185. #define ES_REC_MIXER_RECRECLEV (SOUND_MIXER_RECLEV + ES_REC_MIXER_RECDIFF)
  1186. #define ES_REC_MIXER_RECIGAIN (SOUND_MIXER_IGAIN + ES_REC_MIXER_RECDIFF)
  1187. #define ES_REC_MIXER_RECOGAIN (SOUND_MIXER_OGAIN + ES_REC_MIXER_RECDIFF)
  1188. #define ES_REC_MIXER_RECLINE1 (SOUND_MIXER_LINE1 + ES_REC_MIXER_RECDIFF)
  1189. #define ES_REC_MIXER_RECLINE2 (SOUND_MIXER_LINE2 + ES_REC_MIXER_RECDIFF)
  1190. #define ES_REC_MIXER_RECLINE3 (SOUND_MIXER_LINE3 + ES_REC_MIXER_RECDIFF)
  1191. static mixer_tab es688_mix = {
  1192. MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
  1193. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1194. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1195. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1196. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1197. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1198. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1199. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1200. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1201. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1202. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1203. MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1204. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1205. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1206. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1207. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1208. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1209. };
  1210. /*
  1211. * The ES1688 specifics... hopefully correct...
  1212. * - 6 bit master volume
  1213. * I was wrong, ES1888 docs say ES1688 didn't have it.
  1214. * - RECLEV control
  1215. * These may apply to ES688 too. I have no idea.
  1216. */
  1217. static mixer_tab es1688_mix = {
  1218. MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
  1219. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1220. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1221. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1222. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1223. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1224. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1225. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1226. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1227. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1228. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1229. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1230. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1231. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1232. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1233. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1234. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1235. };
  1236. static mixer_tab es1688later_mix = {
  1237. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1238. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1239. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1240. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1241. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1242. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1243. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1244. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1245. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1246. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1247. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1248. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1249. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1250. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1251. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1252. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1253. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1254. };
  1255. /*
  1256. * This one is for all ESS chips with a record mixer.
  1257. * It's not used (yet) however
  1258. */
  1259. static mixer_tab es_rec_mix = {
  1260. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1261. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1262. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1263. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1264. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1265. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1266. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1267. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1268. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1269. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1270. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1271. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1272. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1273. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1274. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1275. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1276. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
  1277. MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
  1278. MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
  1279. MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
  1280. MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
  1281. MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
  1282. MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
  1283. MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
  1284. MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1285. MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1286. MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1287. MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1288. MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
  1289. MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
  1290. MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
  1291. };
  1292. /*
  1293. * This one is for ES1887. It's little different from es_rec_mix: it
  1294. * has 0x7c for PCM playback level. This is because ES1887 uses
  1295. * Audio 2 for playback.
  1296. */
  1297. static mixer_tab es1887_mix = {
  1298. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1299. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1300. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1301. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1302. MIX_ENT(SOUND_MIXER_PCM, 0x7c, 7, 4, 0x7c, 3, 4),
  1303. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1304. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1305. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1306. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1307. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1308. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1309. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1310. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1311. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1312. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1313. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1314. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
  1315. MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
  1316. MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
  1317. MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
  1318. MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
  1319. MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
  1320. MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
  1321. MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
  1322. MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1323. MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1324. MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1325. MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1326. MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
  1327. MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
  1328. MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
  1329. };
  1330. static int ess_has_rec_mixer (int submodel)
  1331. {
  1332. switch (submodel) {
  1333. case SUBMDL_ES1887:
  1334. return 1;
  1335. default:
  1336. return 0;
  1337. }
  1338. };
  1339. #ifdef FKS_LOGGING
  1340. static int ess_mixer_mon_regs[]
  1341. = { 0x70, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7d, 0x7f
  1342. , 0xa1, 0xa2, 0xa4, 0xa5, 0xa8, 0xa9
  1343. , 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb9
  1344. , 0x00};
  1345. static void ess_show_mixerregs (sb_devc *devc)
  1346. {
  1347. int *mp = ess_mixer_mon_regs;
  1348. return;
  1349. while (*mp != 0) {
  1350. printk (KERN_INFO "res (%x)=%x\n", *mp, (int)(ess_getmixer (devc, *mp)));
  1351. mp++;
  1352. }
  1353. }
  1354. #endif
  1355. void ess_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
  1356. {
  1357. unsigned long flags;
  1358. #ifdef FKS_LOGGING
  1359. printk(KERN_INFO "FKS: write mixer %x: %x\n", port, value);
  1360. #endif
  1361. spin_lock_irqsave(&devc->lock, flags);
  1362. if (port >= 0xa0) {
  1363. ess_write (devc, port, value);
  1364. } else {
  1365. outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
  1366. udelay(20);
  1367. outb(((unsigned char) (value & 0xff)), MIXER_DATA);
  1368. udelay(20);
  1369. }
  1370. spin_unlock_irqrestore(&devc->lock, flags);
  1371. }
  1372. unsigned int ess_getmixer (sb_devc * devc, unsigned int port)
  1373. {
  1374. unsigned int val;
  1375. unsigned long flags;
  1376. spin_lock_irqsave(&devc->lock, flags);
  1377. if (port >= 0xa0) {
  1378. val = ess_read (devc, port);
  1379. } else {
  1380. outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
  1381. udelay(20);
  1382. val = inb(MIXER_DATA);
  1383. udelay(20);
  1384. }
  1385. spin_unlock_irqrestore(&devc->lock, flags);
  1386. return val;
  1387. }
  1388. static void ess_chgmixer
  1389. (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
  1390. {
  1391. int value;
  1392. value = ess_getmixer (devc, reg);
  1393. value = (value & ~mask) | (val & mask);
  1394. ess_setmixer (devc, reg, value);
  1395. }
  1396. /*
  1397. * ess_mixer_init must be called from sb_mixer_init
  1398. */
  1399. void ess_mixer_init (sb_devc * devc)
  1400. {
  1401. devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
  1402. /*
  1403. * Take care of ES1887 specifics...
  1404. */
  1405. switch (devc->submodel) {
  1406. case SUBMDL_ES1887:
  1407. devc->supported_devices = ES1887_MIXER_DEVICES;
  1408. devc->supported_rec_devices = ES1887_RECORDING_DEVICES;
  1409. #ifdef FKS_LOGGING
  1410. printk (KERN_INFO "FKS: ess_mixer_init dup = %d\n", devc->duplex);
  1411. #endif
  1412. if (devc->duplex) {
  1413. devc->iomap = &es1887_mix;
  1414. devc->iomap_sz = ARRAY_SIZE(es1887_mix);
  1415. } else {
  1416. devc->iomap = &es_rec_mix;
  1417. devc->iomap_sz = ARRAY_SIZE(es_rec_mix);
  1418. }
  1419. break;
  1420. default:
  1421. if (devc->submodel < 8) {
  1422. devc->supported_devices = ES688_MIXER_DEVICES;
  1423. devc->supported_rec_devices = ES688_RECORDING_DEVICES;
  1424. devc->iomap = &es688_mix;
  1425. devc->iomap_sz = ARRAY_SIZE(es688_mix);
  1426. } else {
  1427. /*
  1428. * es1688 has 4 bits master vol.
  1429. * later chips have 6 bits (?)
  1430. */
  1431. devc->supported_devices = ES1688_MIXER_DEVICES;
  1432. devc->supported_rec_devices = ES1688_RECORDING_DEVICES;
  1433. if (devc->submodel < 0x10) {
  1434. devc->iomap = &es1688_mix;
  1435. devc->iomap_sz = ARRAY_SIZE(es688_mix);
  1436. } else {
  1437. devc->iomap = &es1688later_mix;
  1438. devc->iomap_sz = ARRAY_SIZE(es1688later_mix);
  1439. }
  1440. }
  1441. }
  1442. }
  1443. /*
  1444. * Changing playback levels at an ESS chip with record mixer means having to
  1445. * take care of recording levels of recorded inputs (devc->recmask) too!
  1446. */
  1447. int ess_mixer_set(sb_devc *devc, int dev, int left, int right)
  1448. {
  1449. if (ess_has_rec_mixer (devc->submodel) && (devc->recmask & (1 << dev))) {
  1450. sb_common_mixer_set (devc, dev + ES_REC_MIXER_RECDIFF, left, right);
  1451. }
  1452. return sb_common_mixer_set (devc, dev, left, right);
  1453. }
  1454. /*
  1455. * After a sb_dsp_reset extended register 0xb4 (RECLEV) is reset too. After
  1456. * sb_dsp_reset RECLEV has to be restored. This is where ess_mixer_reload
  1457. * helps.
  1458. */
  1459. void ess_mixer_reload (sb_devc *devc, int dev)
  1460. {
  1461. int left, right, value;
  1462. value = devc->levels[dev];
  1463. left = value & 0x000000ff;
  1464. right = (value & 0x0000ff00) >> 8;
  1465. sb_common_mixer_set(devc, dev, left, right);
  1466. }
  1467. static int es_rec_set_recmask(sb_devc * devc, int mask)
  1468. {
  1469. int i, i_mask, cur_mask, diff_mask;
  1470. int value, left, right;
  1471. #ifdef FKS_LOGGING
  1472. printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
  1473. #endif
  1474. /*
  1475. * Changing the recmask on an ESS chip with recording mixer means:
  1476. * (1) Find the differences
  1477. * (2) For "turned-on" inputs: make the recording level the playback level
  1478. * (3) For "turned-off" inputs: make the recording level zero
  1479. */
  1480. cur_mask = devc->recmask;
  1481. diff_mask = (cur_mask ^ mask);
  1482. for (i = 0; i < 32; i++) {
  1483. i_mask = (1 << i);
  1484. if (diff_mask & i_mask) { /* Difference? (1) */
  1485. if (mask & i_mask) { /* Turn it on (2) */
  1486. value = devc->levels[i];
  1487. left = value & 0x000000ff;
  1488. right = (value & 0x0000ff00) >> 8;
  1489. } else { /* Turn it off (3) */
  1490. left = 0;
  1491. right = 0;
  1492. }
  1493. sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
  1494. }
  1495. }
  1496. return mask;
  1497. }
  1498. int ess_set_recmask(sb_devc * devc, int *mask)
  1499. {
  1500. /* This applies to ESS chips with record mixers only! */
  1501. if (ess_has_rec_mixer (devc->submodel)) {
  1502. *mask = es_rec_set_recmask (devc, *mask);
  1503. return 1; /* Applied */
  1504. } else {
  1505. return 0; /* Not applied */
  1506. }
  1507. }
  1508. /*
  1509. * ess_mixer_reset must be called from sb_mixer_reset
  1510. */
  1511. int ess_mixer_reset (sb_devc * devc)
  1512. {
  1513. /*
  1514. * Separate actions for ESS chips with a record mixer:
  1515. */
  1516. if (ess_has_rec_mixer (devc->submodel)) {
  1517. switch (devc->submodel) {
  1518. case SUBMDL_ES1887:
  1519. /*
  1520. * Separate actions for ES1887:
  1521. * Change registers 7a and 1c to make the record mixer the
  1522. * actual recording source.
  1523. */
  1524. ess_chgmixer(devc, 0x7a, 0x18, 0x08);
  1525. ess_chgmixer(devc, 0x1c, 0x07, 0x07);
  1526. break;
  1527. }
  1528. /*
  1529. * Call set_recmask for proper initialization
  1530. */
  1531. devc->recmask = devc->supported_rec_devices;
  1532. es_rec_set_recmask(devc, 0);
  1533. devc->recmask = 0;
  1534. return 1; /* We took care of recmask. */
  1535. } else {
  1536. return 0; /* We didn't take care; caller do it */
  1537. }
  1538. }
  1539. /****************************************************************************
  1540. * *
  1541. * ESS midi *
  1542. * *
  1543. ****************************************************************************/
  1544. /*
  1545. * FKS: IRQ may be shared. Hm. And if so? Then What?
  1546. */
  1547. int ess_midi_init(sb_devc * devc, struct address_info *hw_config)
  1548. {
  1549. unsigned char cfg, tmp;
  1550. cfg = ess_getmixer (devc, 0x40) & 0x03;
  1551. if (devc->submodel < 8) {
  1552. ess_setmixer (devc, 0x40, cfg | 0x03); /* Enable OPL3 & joystick */
  1553. return 0; /* ES688 doesn't support MPU401 mode */
  1554. }
  1555. tmp = (hw_config->io_base & 0x0f0) >> 4;
  1556. if (tmp > 3) {
  1557. ess_setmixer (devc, 0x40, cfg);
  1558. return 0;
  1559. }
  1560. cfg |= tmp << 3;
  1561. tmp = 1; /* MPU enabled without interrupts */
  1562. /* May be shared: if so the value is -ve */
  1563. switch (abs(hw_config->irq)) {
  1564. case 9:
  1565. tmp = 0x4;
  1566. break;
  1567. case 5:
  1568. tmp = 0x5;
  1569. break;
  1570. case 7:
  1571. tmp = 0x6;
  1572. break;
  1573. case 10:
  1574. tmp = 0x7;
  1575. break;
  1576. default:
  1577. return 0;
  1578. }
  1579. cfg |= tmp << 5;
  1580. ess_setmixer (devc, 0x40, cfg | 0x03);
  1581. return 1;
  1582. }