sb_ess.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  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. Futhermore 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_WARN "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. DEB(printk("Entered ess_dsp_reset()\n"));
  735. outb(3, DSP_RESET); /* Reset FIFO too */
  736. udelay(10);
  737. outb(0, DSP_RESET);
  738. udelay(30);
  739. for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
  740. if (inb(DSP_READ) != 0xAA) {
  741. DDB(printk("sb: No response to RESET\n"));
  742. return 0; /* Sorry */
  743. }
  744. ess_extended (devc);
  745. DEB(printk("sb_dsp_reset() OK\n"));
  746. #ifdef FKS_LOGGING
  747. printk(KERN_INFO "FKS: dsp_reset 2\n");
  748. ess_show_mixerregs (devc);
  749. #endif
  750. return 1;
  751. }
  752. static int ess_irq_bits (int irq)
  753. {
  754. switch (irq) {
  755. case 2:
  756. case 9:
  757. return 0;
  758. case 5:
  759. return 1;
  760. case 7:
  761. return 2;
  762. case 10:
  763. return 3;
  764. default:
  765. printk(KERN_ERR "ESS1688: Invalid IRQ %d\n", irq);
  766. return -1;
  767. }
  768. }
  769. /*
  770. * Set IRQ configuration register for all ESS models
  771. */
  772. static int ess_common_set_irq_hw (sb_devc * devc)
  773. {
  774. int irq_bits;
  775. if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return 0;
  776. if (!ess_write (devc, 0xb1, 0x50 | (irq_bits << 2))) {
  777. printk(KERN_ERR "ES1688: Failed to write to IRQ config register\n");
  778. return 0;
  779. }
  780. return 1;
  781. }
  782. /*
  783. * I wanna use modern ES1887 mixer irq handling. Funny is the
  784. * fact that my BIOS wants the same. But suppose someone's BIOS
  785. * doesn't do this!
  786. * This is independent of duplex. If there's a 1887 this will
  787. * prevent it from going into 1888 mode.
  788. */
  789. static void ess_es1887_set_irq_hw (sb_devc * devc)
  790. {
  791. int irq_bits;
  792. if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return;
  793. ess_chgmixer (devc, 0x7f, 0x0f, 0x01 | ((irq_bits + 1) << 1));
  794. }
  795. static int ess_set_irq_hw (sb_devc * devc)
  796. {
  797. if (devc->submodel == SUBMDL_ES1887) ess_es1887_set_irq_hw (devc);
  798. return ess_common_set_irq_hw (devc);
  799. }
  800. #ifdef FKS_TEST
  801. /*
  802. * FKS_test:
  803. * for ES1887: 00, 18, non wr bits: 0001 1000
  804. * for ES1868: 00, b8, non wr bits: 1011 1000
  805. * for ES1888: 00, f8, non wr bits: 1111 1000
  806. * for ES1688: 00, f8, non wr bits: 1111 1000
  807. * + ES968
  808. */
  809. static void FKS_test (sb_devc * devc)
  810. {
  811. int val1, val2;
  812. val1 = ess_getmixer (devc, 0x64);
  813. ess_setmixer (devc, 0x64, ~val1);
  814. val2 = ess_getmixer (devc, 0x64) ^ ~val1;
  815. ess_setmixer (devc, 0x64, val1);
  816. val1 ^= ess_getmixer (devc, 0x64);
  817. printk (KERN_INFO "FKS: FKS_test %02x, %02x\n", (val1 & 0x0ff), (val2 & 0x0ff));
  818. };
  819. #endif
  820. static unsigned int ess_identify (sb_devc * devc)
  821. {
  822. unsigned int val;
  823. unsigned long flags;
  824. spin_lock_irqsave(&devc->lock, flags);
  825. outb(((unsigned char) (0x40 & 0xff)), MIXER_ADDR);
  826. udelay(20);
  827. val = inb(MIXER_DATA) << 8;
  828. udelay(20);
  829. val |= inb(MIXER_DATA);
  830. udelay(20);
  831. spin_unlock_irqrestore(&devc->lock, flags);
  832. return val;
  833. }
  834. /*
  835. * ESS technology describes a detection scheme in their docs. It involves
  836. * fiddling with the bits in certain mixer registers. ess_probe is supposed
  837. * to help.
  838. *
  839. * FKS: tracing shows ess_probe writes wrong value to 0x64. Bit 3 reads 1, but
  840. * should be written 0 only. Check this.
  841. */
  842. static int ess_probe (sb_devc * devc, int reg, int xorval)
  843. {
  844. int val1, val2, val3;
  845. val1 = ess_getmixer (devc, reg);
  846. val2 = val1 ^ xorval;
  847. ess_setmixer (devc, reg, val2);
  848. val3 = ess_getmixer (devc, reg);
  849. ess_setmixer (devc, reg, val1);
  850. return (val2 == val3);
  851. }
  852. int ess_init(sb_devc * devc, struct address_info *hw_config)
  853. {
  854. unsigned char cfg;
  855. int ess_major = 0, ess_minor = 0;
  856. int i;
  857. static char name[100], modelname[10];
  858. /*
  859. * Try to detect ESS chips.
  860. */
  861. sb_dsp_command(devc, 0xe7); /* Return identification */
  862. for (i = 1000; i; i--) {
  863. if (inb(DSP_DATA_AVAIL) & 0x80) {
  864. if (ess_major == 0) {
  865. ess_major = inb(DSP_READ);
  866. } else {
  867. ess_minor = inb(DSP_READ);
  868. break;
  869. }
  870. }
  871. }
  872. if (ess_major == 0) return 0;
  873. if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80) {
  874. sprintf(name, "ESS ES488 AudioDrive (rev %d)",
  875. ess_minor & 0x0f);
  876. hw_config->name = name;
  877. devc->model = MDL_SBPRO;
  878. return 1;
  879. }
  880. /*
  881. * This the detection heuristic of ESS technology, though somewhat
  882. * changed to actually make it work.
  883. * This results in the following detection steps:
  884. * - distinct between ES688 and ES1688+ (as always done in this driver)
  885. * if ES688 we're ready
  886. * - try to detect ES1868, ES1869 or ES1878 (ess_identify)
  887. * if successful we're ready
  888. * - try to detect ES1888, ES1887 or ES1788 (aim: detect ES1887)
  889. * if successful we're ready
  890. * - Dunno. Must be 1688. Will do in general
  891. *
  892. * This is the most BETA part of the software: Will the detection
  893. * always work?
  894. */
  895. devc->model = MDL_ESS;
  896. devc->submodel = ess_minor & 0x0f;
  897. if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80) {
  898. char *chip = NULL;
  899. int submodel = -1;
  900. switch (devc->sbmo.esstype) {
  901. case ESSTYPE_DETECT:
  902. case ESSTYPE_LIKE20:
  903. break;
  904. case 688:
  905. submodel = 0x00;
  906. break;
  907. case 1688:
  908. submodel = 0x08;
  909. break;
  910. case 1868:
  911. submodel = SUBMDL_ES1868;
  912. break;
  913. case 1869:
  914. submodel = SUBMDL_ES1869;
  915. break;
  916. case 1788:
  917. submodel = SUBMDL_ES1788;
  918. break;
  919. case 1878:
  920. submodel = SUBMDL_ES1878;
  921. break;
  922. case 1879:
  923. submodel = SUBMDL_ES1879;
  924. break;
  925. case 1887:
  926. submodel = SUBMDL_ES1887;
  927. break;
  928. case 1888:
  929. submodel = SUBMDL_ES1888;
  930. break;
  931. default:
  932. printk (KERN_ERR "Invalid esstype=%d specified\n", devc->sbmo.esstype);
  933. return 0;
  934. };
  935. if (submodel != -1) {
  936. devc->submodel = submodel;
  937. sprintf (modelname, "ES%d", devc->sbmo.esstype);
  938. chip = modelname;
  939. };
  940. if (chip == NULL && (ess_minor & 0x0f) < 8) {
  941. chip = "ES688";
  942. };
  943. #ifdef FKS_TEST
  944. FKS_test (devc);
  945. #endif
  946. /*
  947. * If Nothing detected yet, and we want 2.0 behaviour...
  948. * Then let's assume it's ES1688.
  949. */
  950. if (chip == NULL && devc->sbmo.esstype == ESSTYPE_LIKE20) {
  951. chip = "ES1688";
  952. };
  953. if (chip == NULL) {
  954. int type;
  955. type = ess_identify (devc);
  956. switch (type) {
  957. case 0x1868:
  958. chip = "ES1868";
  959. devc->submodel = SUBMDL_ES1868;
  960. break;
  961. case 0x1869:
  962. chip = "ES1869";
  963. devc->submodel = SUBMDL_ES1869;
  964. break;
  965. case 0x1878:
  966. chip = "ES1878";
  967. devc->submodel = SUBMDL_ES1878;
  968. break;
  969. case 0x1879:
  970. chip = "ES1879";
  971. devc->submodel = SUBMDL_ES1879;
  972. break;
  973. default:
  974. if ((type & 0x00ff) != ((type >> 8) & 0x00ff)) {
  975. printk ("ess_init: Unrecognized %04x\n", type);
  976. }
  977. };
  978. };
  979. #if 0
  980. /*
  981. * this one failed:
  982. * the probing of bit 4 is another thought: from ES1788 and up, all
  983. * chips seem to have hardware volume control. Bit 4 is readonly to
  984. * check if a hardware volume interrupt has fired.
  985. * Cause ES688/ES1688 don't have this feature, bit 4 might be writeable
  986. * for these chips.
  987. */
  988. if (chip == NULL && !ess_probe(devc, 0x64, (1 << 4))) {
  989. #endif
  990. /*
  991. * the probing of bit 2 is my idea. The ES1887 docs want me to probe
  992. * bit 3. This results in ES1688 being detected as ES1788.
  993. * Bit 2 is for "Enable HWV IRQE", but as ES(1)688 chips don't have
  994. * HardWare Volume, I think they don't have this IRQE.
  995. */
  996. if (chip == NULL && ess_probe(devc, 0x64, (1 << 2))) {
  997. if (ess_probe (devc, 0x70, 0x7f)) {
  998. if (ess_probe (devc, 0x64, (1 << 5))) {
  999. chip = "ES1887";
  1000. devc->submodel = SUBMDL_ES1887;
  1001. } else {
  1002. chip = "ES1888";
  1003. devc->submodel = SUBMDL_ES1888;
  1004. }
  1005. } else {
  1006. chip = "ES1788";
  1007. devc->submodel = SUBMDL_ES1788;
  1008. }
  1009. };
  1010. if (chip == NULL) {
  1011. chip = "ES1688";
  1012. };
  1013. printk ( KERN_INFO "ESS chip %s %s%s\n"
  1014. , chip
  1015. , ( devc->sbmo.esstype == ESSTYPE_DETECT || devc->sbmo.esstype == ESSTYPE_LIKE20
  1016. ? "detected"
  1017. : "specified"
  1018. )
  1019. , ( devc->sbmo.esstype == ESSTYPE_LIKE20
  1020. ? " (kernel 2.0 compatible)"
  1021. : ""
  1022. )
  1023. );
  1024. sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
  1025. } else {
  1026. strcpy(name, "Jazz16");
  1027. }
  1028. /* AAS: info stolen from ALSA: these boards have different clocks */
  1029. switch(devc->submodel) {
  1030. /* APPARENTLY NOT 1869 AND 1887
  1031. case SUBMDL_ES1869:
  1032. case SUBMDL_ES1887:
  1033. */
  1034. case SUBMDL_ES1888:
  1035. devc->caps |= SB_CAP_ES18XX_RATE;
  1036. break;
  1037. }
  1038. hw_config->name = name;
  1039. /* FKS: sb_dsp_reset to enable extended mode???? */
  1040. sb_dsp_reset(devc); /* Turn on extended mode */
  1041. /*
  1042. * Enable joystick and OPL3
  1043. */
  1044. cfg = ess_getmixer (devc, 0x40);
  1045. ess_setmixer (devc, 0x40, cfg | 0x03);
  1046. if (devc->submodel >= 8) { /* ES1688 */
  1047. devc->caps |= SB_NO_MIDI; /* ES1688 uses MPU401 MIDI mode */
  1048. }
  1049. sb_dsp_reset (devc);
  1050. /*
  1051. * This is important! If it's not done, the IRQ probe in sb_dsp_init
  1052. * may fail.
  1053. */
  1054. return ess_set_irq_hw (devc);
  1055. }
  1056. static int ess_set_dma_hw(sb_devc * devc)
  1057. {
  1058. unsigned char cfg, dma_bits = 0, dma16_bits;
  1059. int dma;
  1060. #ifdef FKS_LOGGING
  1061. printk(KERN_INFO "ess_set_dma_hw: dma8=%d,dma16=%d,dup=%d\n"
  1062. , devc->dma8, devc->dma16, devc->duplex);
  1063. #endif
  1064. /*
  1065. * FKS: It seems as if this duplex flag isn't set yet. Check it.
  1066. */
  1067. dma = devc->dma8;
  1068. if (dma > 3 || dma < 0 || dma == 2) {
  1069. dma_bits = 0;
  1070. printk(KERN_ERR "ESS1688: Invalid DMA8 %d\n", dma);
  1071. return 0;
  1072. } else {
  1073. /* Extended mode DMA enable */
  1074. cfg = 0x50;
  1075. if (dma == 3) {
  1076. dma_bits = 3;
  1077. } else {
  1078. dma_bits = dma + 1;
  1079. }
  1080. }
  1081. if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2))) {
  1082. printk(KERN_ERR "ESS1688: Failed to write to DMA config register\n");
  1083. return 0;
  1084. }
  1085. if (devc->duplex) {
  1086. dma = devc->dma16;
  1087. dma16_bits = 0;
  1088. if (dma >= 0) {
  1089. switch (dma) {
  1090. case 0:
  1091. dma_bits = 0x04;
  1092. break;
  1093. case 1:
  1094. dma_bits = 0x05;
  1095. break;
  1096. case 3:
  1097. dma_bits = 0x06;
  1098. break;
  1099. case 5:
  1100. dma_bits = 0x07;
  1101. dma16_bits = 0x20;
  1102. break;
  1103. default:
  1104. printk(KERN_ERR "ESS1887: Invalid DMA16 %d\n", dma);
  1105. return 0;
  1106. };
  1107. ess_chgmixer (devc, 0x78, 0x20, dma16_bits);
  1108. ess_chgmixer (devc, 0x7d, 0x07, dma_bits);
  1109. }
  1110. }
  1111. return 1;
  1112. }
  1113. /*
  1114. * This one is called from sb_dsp_init.
  1115. *
  1116. * Return values:
  1117. * 0: Failed
  1118. * 1: Succeeded or doesn't apply (not SUBMDL_ES1887)
  1119. */
  1120. int ess_dsp_init (sb_devc *devc, struct address_info *hw_config)
  1121. {
  1122. /*
  1123. * Caller also checks this, but anyway
  1124. */
  1125. if (devc->model != MDL_ESS) {
  1126. printk (KERN_INFO "ess_dsp_init for non ESS chip\n");
  1127. return 1;
  1128. }
  1129. /*
  1130. * This for ES1887 to run Full Duplex. Actually ES1888
  1131. * is allowed to do so too. I have no idea yet if this
  1132. * will work for ES1888 however.
  1133. *
  1134. * For SB16 having both dma8 and dma16 means enable
  1135. * Full Duplex. Let's try this for ES1887 too
  1136. *
  1137. */
  1138. if (devc->submodel == SUBMDL_ES1887) {
  1139. if (hw_config->dma2 != -1) {
  1140. devc->dma16 = hw_config->dma2;
  1141. }
  1142. /*
  1143. * devc->duplex initialization is put here, cause
  1144. * ess_set_dma_hw needs it.
  1145. */
  1146. if (devc->dma8 != devc->dma16 && devc->dma16 != -1) {
  1147. devc->duplex = 1;
  1148. }
  1149. }
  1150. if (!ess_set_dma_hw (devc)) {
  1151. free_irq(devc->irq, devc);
  1152. return 0;
  1153. }
  1154. return 1;
  1155. }
  1156. /****************************************************************************
  1157. * *
  1158. * ESS mixer *
  1159. * *
  1160. ****************************************************************************/
  1161. #define ES688_RECORDING_DEVICES \
  1162. ( SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD )
  1163. #define ES688_MIXER_DEVICES \
  1164. ( SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE \
  1165. | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME \
  1166. | SOUND_MASK_LINE2 | SOUND_MASK_SPEAKER )
  1167. #define ES1688_RECORDING_DEVICES \
  1168. ( ES688_RECORDING_DEVICES )
  1169. #define ES1688_MIXER_DEVICES \
  1170. ( ES688_MIXER_DEVICES | SOUND_MASK_RECLEV )
  1171. #define ES1887_RECORDING_DEVICES \
  1172. ( ES1688_RECORDING_DEVICES | SOUND_MASK_LINE2 | SOUND_MASK_SYNTH)
  1173. #define ES1887_MIXER_DEVICES \
  1174. ( ES1688_MIXER_DEVICES )
  1175. /*
  1176. * Mixer registers of ES1887
  1177. *
  1178. * These registers specifically take care of recording levels. To make the
  1179. * mapping from playback devices to recording devices every recording
  1180. * devices = playback device + ES_REC_MIXER_RECDIFF
  1181. */
  1182. #define ES_REC_MIXER_RECBASE (SOUND_MIXER_LINE3 + 1)
  1183. #define ES_REC_MIXER_RECDIFF (ES_REC_MIXER_RECBASE - SOUND_MIXER_SYNTH)
  1184. #define ES_REC_MIXER_RECSYNTH (SOUND_MIXER_SYNTH + ES_REC_MIXER_RECDIFF)
  1185. #define ES_REC_MIXER_RECPCM (SOUND_MIXER_PCM + ES_REC_MIXER_RECDIFF)
  1186. #define ES_REC_MIXER_RECSPEAKER (SOUND_MIXER_SPEAKER + ES_REC_MIXER_RECDIFF)
  1187. #define ES_REC_MIXER_RECLINE (SOUND_MIXER_LINE + ES_REC_MIXER_RECDIFF)
  1188. #define ES_REC_MIXER_RECMIC (SOUND_MIXER_MIC + ES_REC_MIXER_RECDIFF)
  1189. #define ES_REC_MIXER_RECCD (SOUND_MIXER_CD + ES_REC_MIXER_RECDIFF)
  1190. #define ES_REC_MIXER_RECIMIX (SOUND_MIXER_IMIX + ES_REC_MIXER_RECDIFF)
  1191. #define ES_REC_MIXER_RECALTPCM (SOUND_MIXER_ALTPCM + ES_REC_MIXER_RECDIFF)
  1192. #define ES_REC_MIXER_RECRECLEV (SOUND_MIXER_RECLEV + ES_REC_MIXER_RECDIFF)
  1193. #define ES_REC_MIXER_RECIGAIN (SOUND_MIXER_IGAIN + ES_REC_MIXER_RECDIFF)
  1194. #define ES_REC_MIXER_RECOGAIN (SOUND_MIXER_OGAIN + ES_REC_MIXER_RECDIFF)
  1195. #define ES_REC_MIXER_RECLINE1 (SOUND_MIXER_LINE1 + ES_REC_MIXER_RECDIFF)
  1196. #define ES_REC_MIXER_RECLINE2 (SOUND_MIXER_LINE2 + ES_REC_MIXER_RECDIFF)
  1197. #define ES_REC_MIXER_RECLINE3 (SOUND_MIXER_LINE3 + ES_REC_MIXER_RECDIFF)
  1198. static mixer_tab es688_mix = {
  1199. MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
  1200. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1201. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1202. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1203. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1204. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1205. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1206. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1207. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1208. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1209. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1210. MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1211. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1212. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1213. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1214. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1215. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1216. };
  1217. /*
  1218. * The ES1688 specifics... hopefully correct...
  1219. * - 6 bit master volume
  1220. * I was wrong, ES1888 docs say ES1688 didn't have it.
  1221. * - RECLEV control
  1222. * These may apply to ES688 too. I have no idea.
  1223. */
  1224. static mixer_tab es1688_mix = {
  1225. MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
  1226. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1227. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1228. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1229. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1230. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1231. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1232. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1233. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1234. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1235. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1236. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1237. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1238. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1239. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1240. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1241. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1242. };
  1243. static mixer_tab es1688later_mix = {
  1244. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1245. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1246. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1247. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1248. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1249. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1250. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1251. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1252. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1253. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1254. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1255. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1256. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1257. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1258. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1259. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1260. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
  1261. };
  1262. /*
  1263. * This one is for all ESS chips with a record mixer.
  1264. * It's not used (yet) however
  1265. */
  1266. static mixer_tab es_rec_mix = {
  1267. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1268. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1269. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1270. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1271. MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
  1272. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1273. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1274. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1275. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1276. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1277. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1278. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1279. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1280. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1281. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1282. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1283. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
  1284. MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
  1285. MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
  1286. MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
  1287. MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
  1288. MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
  1289. MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
  1290. MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
  1291. MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1292. MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1293. MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1294. MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1295. MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
  1296. MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
  1297. MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
  1298. };
  1299. /*
  1300. * This one is for ES1887. It's little different from es_rec_mix: it
  1301. * has 0x7c for PCM playback level. This is because ES1887 uses
  1302. * Audio 2 for playback.
  1303. */
  1304. static mixer_tab es1887_mix = {
  1305. MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
  1306. MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
  1307. MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
  1308. MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
  1309. MIX_ENT(SOUND_MIXER_PCM, 0x7c, 7, 4, 0x7c, 3, 4),
  1310. MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
  1311. MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
  1312. MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
  1313. MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
  1314. MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
  1315. MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1316. MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
  1317. MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1318. MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1319. MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
  1320. MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
  1321. MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
  1322. MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
  1323. MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
  1324. MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
  1325. MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
  1326. MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
  1327. MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
  1328. MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
  1329. MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
  1330. MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
  1331. MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1332. MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
  1333. MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
  1334. MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
  1335. MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
  1336. };
  1337. static int ess_has_rec_mixer (int submodel)
  1338. {
  1339. switch (submodel) {
  1340. case SUBMDL_ES1887:
  1341. return 1;
  1342. default:
  1343. return 0;
  1344. };
  1345. };
  1346. #ifdef FKS_LOGGING
  1347. static int ess_mixer_mon_regs[]
  1348. = { 0x70, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7d, 0x7f
  1349. , 0xa1, 0xa2, 0xa4, 0xa5, 0xa8, 0xa9
  1350. , 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb9
  1351. , 0x00};
  1352. static void ess_show_mixerregs (sb_devc *devc)
  1353. {
  1354. int *mp = ess_mixer_mon_regs;
  1355. return;
  1356. while (*mp != 0) {
  1357. printk (KERN_INFO "res (%x)=%x\n", *mp, (int)(ess_getmixer (devc, *mp)));
  1358. mp++;
  1359. }
  1360. }
  1361. #endif
  1362. void ess_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
  1363. {
  1364. unsigned long flags;
  1365. #ifdef FKS_LOGGING
  1366. printk(KERN_INFO "FKS: write mixer %x: %x\n", port, value);
  1367. #endif
  1368. spin_lock_irqsave(&devc->lock, flags);
  1369. if (port >= 0xa0) {
  1370. ess_write (devc, port, value);
  1371. } else {
  1372. outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
  1373. udelay(20);
  1374. outb(((unsigned char) (value & 0xff)), MIXER_DATA);
  1375. udelay(20);
  1376. };
  1377. spin_unlock_irqrestore(&devc->lock, flags);
  1378. }
  1379. unsigned int ess_getmixer (sb_devc * devc, unsigned int port)
  1380. {
  1381. unsigned int val;
  1382. unsigned long flags;
  1383. spin_lock_irqsave(&devc->lock, flags);
  1384. if (port >= 0xa0) {
  1385. val = ess_read (devc, port);
  1386. } else {
  1387. outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
  1388. udelay(20);
  1389. val = inb(MIXER_DATA);
  1390. udelay(20);
  1391. }
  1392. spin_unlock_irqrestore(&devc->lock, flags);
  1393. return val;
  1394. }
  1395. static void ess_chgmixer
  1396. (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
  1397. {
  1398. int value;
  1399. value = ess_getmixer (devc, reg);
  1400. value = (value & ~mask) | (val & mask);
  1401. ess_setmixer (devc, reg, value);
  1402. }
  1403. /*
  1404. * ess_mixer_init must be called from sb_mixer_init
  1405. */
  1406. void ess_mixer_init (sb_devc * devc)
  1407. {
  1408. devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
  1409. /*
  1410. * Take care of ES1887 specifics...
  1411. */
  1412. switch (devc->submodel) {
  1413. case SUBMDL_ES1887:
  1414. devc->supported_devices = ES1887_MIXER_DEVICES;
  1415. devc->supported_rec_devices = ES1887_RECORDING_DEVICES;
  1416. #ifdef FKS_LOGGING
  1417. printk (KERN_INFO "FKS: ess_mixer_init dup = %d\n", devc->duplex);
  1418. #endif
  1419. if (devc->duplex) {
  1420. devc->iomap = &es1887_mix;
  1421. devc->iomap_sz = ARRAY_SIZE(es1887_mix);
  1422. } else {
  1423. devc->iomap = &es_rec_mix;
  1424. devc->iomap_sz = ARRAY_SIZE(es_rec_mix);
  1425. }
  1426. break;
  1427. default:
  1428. if (devc->submodel < 8) {
  1429. devc->supported_devices = ES688_MIXER_DEVICES;
  1430. devc->supported_rec_devices = ES688_RECORDING_DEVICES;
  1431. devc->iomap = &es688_mix;
  1432. devc->iomap_sz = ARRAY_SIZE(es688_mix);
  1433. } else {
  1434. /*
  1435. * es1688 has 4 bits master vol.
  1436. * later chips have 6 bits (?)
  1437. */
  1438. devc->supported_devices = ES1688_MIXER_DEVICES;
  1439. devc->supported_rec_devices = ES1688_RECORDING_DEVICES;
  1440. if (devc->submodel < 0x10) {
  1441. devc->iomap = &es1688_mix;
  1442. devc->iomap_sz = ARRAY_SIZE(es688_mix);
  1443. } else {
  1444. devc->iomap = &es1688later_mix;
  1445. devc->iomap_sz = ARRAY_SIZE(es1688later_mix);
  1446. }
  1447. }
  1448. }
  1449. }
  1450. /*
  1451. * Changing playback levels at an ESS chip with record mixer means having to
  1452. * take care of recording levels of recorded inputs (devc->recmask) too!
  1453. */
  1454. int ess_mixer_set(sb_devc *devc, int dev, int left, int right)
  1455. {
  1456. if (ess_has_rec_mixer (devc->submodel) && (devc->recmask & (1 << dev))) {
  1457. sb_common_mixer_set (devc, dev + ES_REC_MIXER_RECDIFF, left, right);
  1458. }
  1459. return sb_common_mixer_set (devc, dev, left, right);
  1460. }
  1461. /*
  1462. * After a sb_dsp_reset extended register 0xb4 (RECLEV) is reset too. After
  1463. * sb_dsp_reset RECLEV has to be restored. This is where ess_mixer_reload
  1464. * helps.
  1465. */
  1466. void ess_mixer_reload (sb_devc *devc, int dev)
  1467. {
  1468. int left, right, value;
  1469. value = devc->levels[dev];
  1470. left = value & 0x000000ff;
  1471. right = (value & 0x0000ff00) >> 8;
  1472. sb_common_mixer_set(devc, dev, left, right);
  1473. }
  1474. static int es_rec_set_recmask(sb_devc * devc, int mask)
  1475. {
  1476. int i, i_mask, cur_mask, diff_mask;
  1477. int value, left, right;
  1478. #ifdef FKS_LOGGING
  1479. printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
  1480. #endif
  1481. /*
  1482. * Changing the recmask on an ESS chip with recording mixer means:
  1483. * (1) Find the differences
  1484. * (2) For "turned-on" inputs: make the recording level the playback level
  1485. * (3) For "turned-off" inputs: make the recording level zero
  1486. */
  1487. cur_mask = devc->recmask;
  1488. diff_mask = (cur_mask ^ mask);
  1489. for (i = 0; i < 32; i++) {
  1490. i_mask = (1 << i);
  1491. if (diff_mask & i_mask) { /* Difference? (1) */
  1492. if (mask & i_mask) { /* Turn it on (2) */
  1493. value = devc->levels[i];
  1494. left = value & 0x000000ff;
  1495. right = (value & 0x0000ff00) >> 8;
  1496. } else { /* Turn it off (3) */
  1497. left = 0;
  1498. left = 0;
  1499. right = 0;
  1500. }
  1501. sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
  1502. }
  1503. }
  1504. return mask;
  1505. }
  1506. int ess_set_recmask(sb_devc * devc, int *mask)
  1507. {
  1508. /* This applies to ESS chips with record mixers only! */
  1509. if (ess_has_rec_mixer (devc->submodel)) {
  1510. *mask = es_rec_set_recmask (devc, *mask);
  1511. return 1; /* Applied */
  1512. } else {
  1513. return 0; /* Not applied */
  1514. }
  1515. }
  1516. /*
  1517. * ess_mixer_reset must be called from sb_mixer_reset
  1518. */
  1519. int ess_mixer_reset (sb_devc * devc)
  1520. {
  1521. /*
  1522. * Separate actions for ESS chips with a record mixer:
  1523. */
  1524. if (ess_has_rec_mixer (devc->submodel)) {
  1525. switch (devc->submodel) {
  1526. case SUBMDL_ES1887:
  1527. /*
  1528. * Separate actions for ES1887:
  1529. * Change registers 7a and 1c to make the record mixer the
  1530. * actual recording source.
  1531. */
  1532. ess_chgmixer(devc, 0x7a, 0x18, 0x08);
  1533. ess_chgmixer(devc, 0x1c, 0x07, 0x07);
  1534. break;
  1535. };
  1536. /*
  1537. * Call set_recmask for proper initialization
  1538. */
  1539. devc->recmask = devc->supported_rec_devices;
  1540. es_rec_set_recmask(devc, 0);
  1541. devc->recmask = 0;
  1542. return 1; /* We took care of recmask. */
  1543. } else {
  1544. return 0; /* We didn't take care; caller do it */
  1545. }
  1546. }
  1547. /****************************************************************************
  1548. * *
  1549. * ESS midi *
  1550. * *
  1551. ****************************************************************************/
  1552. /*
  1553. * FKS: IRQ may be shared. Hm. And if so? Then What?
  1554. */
  1555. int ess_midi_init(sb_devc * devc, struct address_info *hw_config)
  1556. {
  1557. unsigned char cfg, tmp;
  1558. cfg = ess_getmixer (devc, 0x40) & 0x03;
  1559. if (devc->submodel < 8) {
  1560. ess_setmixer (devc, 0x40, cfg | 0x03); /* Enable OPL3 & joystick */
  1561. return 0; /* ES688 doesn't support MPU401 mode */
  1562. }
  1563. tmp = (hw_config->io_base & 0x0f0) >> 4;
  1564. if (tmp > 3) {
  1565. ess_setmixer (devc, 0x40, cfg);
  1566. return 0;
  1567. }
  1568. cfg |= tmp << 3;
  1569. tmp = 1; /* MPU enabled without interrupts */
  1570. /* May be shared: if so the value is -ve */
  1571. switch (abs(hw_config->irq)) {
  1572. case 9:
  1573. tmp = 0x4;
  1574. break;
  1575. case 5:
  1576. tmp = 0x5;
  1577. break;
  1578. case 7:
  1579. tmp = 0x6;
  1580. break;
  1581. case 10:
  1582. tmp = 0x7;
  1583. break;
  1584. default:
  1585. return 0;
  1586. }
  1587. cfg |= tmp << 5;
  1588. ess_setmixer (devc, 0x40, cfg | 0x03);
  1589. return 1;
  1590. }