sb_ess.c 51 KB

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