es1688_lib.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * Routines for control of ESS ES1688/688/488 chip
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <linux/ioport.h>
  27. #include <sound/core.h>
  28. #include <sound/es1688.h>
  29. #include <sound/initval.h>
  30. #include <asm/io.h>
  31. #include <asm/dma.h>
  32. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  33. MODULE_DESCRIPTION("ESS ESx688 lowlevel module");
  34. MODULE_LICENSE("GPL");
  35. static int snd_es1688_dsp_command(es1688_t *chip, unsigned char val)
  36. {
  37. int i;
  38. for (i = 10000; i; i--)
  39. if ((inb(ES1688P(chip, STATUS)) & 0x80) == 0) {
  40. outb(val, ES1688P(chip, COMMAND));
  41. return 1;
  42. }
  43. #ifdef CONFIG_SND_DEBUG
  44. printk("snd_es1688_dsp_command: timeout (0x%x)\n", val);
  45. #endif
  46. return 0;
  47. }
  48. static int snd_es1688_dsp_get_byte(es1688_t *chip)
  49. {
  50. int i;
  51. for (i = 1000; i; i--)
  52. if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80)
  53. return inb(ES1688P(chip, READ));
  54. snd_printd("es1688 get byte failed: 0x%lx = 0x%x!!!\n", ES1688P(chip, DATA_AVAIL), inb(ES1688P(chip, DATA_AVAIL)));
  55. return -ENODEV;
  56. }
  57. static int snd_es1688_write(es1688_t *chip,
  58. unsigned char reg, unsigned char data)
  59. {
  60. if (!snd_es1688_dsp_command(chip, reg))
  61. return 0;
  62. return snd_es1688_dsp_command(chip, data);
  63. }
  64. static int snd_es1688_read(es1688_t *chip, unsigned char reg)
  65. {
  66. /* Read a byte from an extended mode register of ES1688 */
  67. if (!snd_es1688_dsp_command(chip, 0xc0))
  68. return -1;
  69. if (!snd_es1688_dsp_command(chip, reg))
  70. return -1;
  71. return snd_es1688_dsp_get_byte(chip);
  72. }
  73. void snd_es1688_mixer_write(es1688_t *chip,
  74. unsigned char reg, unsigned char data)
  75. {
  76. outb(reg, ES1688P(chip, MIXER_ADDR));
  77. udelay(10);
  78. outb(data, ES1688P(chip, MIXER_DATA));
  79. udelay(10);
  80. }
  81. static unsigned char snd_es1688_mixer_read(es1688_t *chip, unsigned char reg)
  82. {
  83. unsigned char result;
  84. outb(reg, ES1688P(chip, MIXER_ADDR));
  85. udelay(10);
  86. result = inb(ES1688P(chip, MIXER_DATA));
  87. udelay(10);
  88. return result;
  89. }
  90. static int snd_es1688_reset(es1688_t *chip)
  91. {
  92. int i;
  93. outb(3, ES1688P(chip, RESET)); /* valid only for ESS chips, SB -> 1 */
  94. udelay(10);
  95. outb(0, ES1688P(chip, RESET));
  96. udelay(30);
  97. for (i = 0; i < 1000 && !(inb(ES1688P(chip, DATA_AVAIL)) & 0x80); i++);
  98. if (inb(ES1688P(chip, READ)) != 0xaa) {
  99. snd_printd("ess_reset at 0x%lx: failed!!!\n", chip->port);
  100. return -ENODEV;
  101. }
  102. snd_es1688_dsp_command(chip, 0xc6); /* enable extended mode */
  103. return 0;
  104. }
  105. static int snd_es1688_probe(es1688_t *chip)
  106. {
  107. unsigned long flags;
  108. unsigned short major, minor, hw;
  109. int i;
  110. /*
  111. * initialization sequence
  112. */
  113. spin_lock_irqsave(&chip->reg_lock, flags); /* Some ESS1688 cards need this */
  114. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  115. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  116. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  117. inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
  118. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  119. inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
  120. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  121. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  122. inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
  123. inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
  124. inb(ES1688P(chip, ENABLE0)); /* ENABLE0 */
  125. if (snd_es1688_reset(chip) < 0) {
  126. snd_printdd("ESS: [0x%lx] reset failed... 0x%x\n", chip->port, inb(ES1688P(chip, READ)));
  127. spin_unlock_irqrestore(&chip->reg_lock, flags);
  128. return -ENODEV;
  129. }
  130. snd_es1688_dsp_command(chip, 0xe7); /* return identification */
  131. for (i = 1000, major = minor = 0; i; i--) {
  132. if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80) {
  133. if (major == 0) {
  134. major = inb(ES1688P(chip, READ));
  135. } else {
  136. minor = inb(ES1688P(chip, READ));
  137. }
  138. }
  139. }
  140. spin_unlock_irqrestore(&chip->reg_lock, flags);
  141. snd_printdd("ESS: [0x%lx] found.. major = 0x%x, minor = 0x%x\n", chip->port, major, minor);
  142. chip->version = (major << 8) | minor;
  143. if (!chip->version)
  144. return -ENODEV; /* probably SB */
  145. hw = ES1688_HW_AUTO;
  146. switch (chip->version & 0xfff0) {
  147. case 0x4880:
  148. snd_printk("[0x%lx] ESS: AudioDrive ES488 detected, but driver is in another place\n", chip->port);
  149. return -ENODEV;
  150. case 0x6880:
  151. hw = (chip->version & 0x0f) >= 8 ? ES1688_HW_1688 : ES1688_HW_688;
  152. break;
  153. default:
  154. snd_printk("[0x%lx] ESS: unknown AudioDrive chip with version 0x%x (Jazz16 soundcard?)\n", chip->port, chip->version);
  155. return -ENODEV;
  156. }
  157. spin_lock_irqsave(&chip->reg_lock, flags);
  158. snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */
  159. snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */
  160. spin_unlock_irqrestore(&chip->reg_lock, flags);
  161. /* enable joystick, but disable OPL3 */
  162. spin_lock_irqsave(&chip->mixer_lock, flags);
  163. snd_es1688_mixer_write(chip, 0x40, 0x01);
  164. spin_unlock_irqrestore(&chip->mixer_lock, flags);
  165. return 0;
  166. }
  167. static int snd_es1688_init(es1688_t * chip, int enable)
  168. {
  169. static int irqs[16] = {-1, -1, 0, -1, -1, 1, -1, 2, -1, 0, 3, -1, -1, -1, -1, -1};
  170. unsigned long flags;
  171. int cfg, irq_bits, dma, dma_bits, tmp, tmp1;
  172. /* ok.. setup MPU-401 port and joystick and OPL3 */
  173. cfg = 0x01; /* enable joystick, but disable OPL3 */
  174. if (enable && chip->mpu_port >= 0x300 && chip->mpu_irq > 0 && chip->hardware != ES1688_HW_688) {
  175. tmp = (chip->mpu_port & 0x0f0) >> 4;
  176. if (tmp <= 3) {
  177. switch (chip->mpu_irq) {
  178. case 9:
  179. tmp1 = 4;
  180. break;
  181. case 5:
  182. tmp1 = 5;
  183. break;
  184. case 7:
  185. tmp1 = 6;
  186. break;
  187. case 10:
  188. tmp1 = 7;
  189. break;
  190. default:
  191. tmp1 = 0;
  192. }
  193. if (tmp1) {
  194. cfg |= (tmp << 3) | (tmp1 << 5);
  195. }
  196. }
  197. }
  198. #if 0
  199. snd_printk("mpu cfg = 0x%x\n", cfg);
  200. #endif
  201. spin_lock_irqsave(&chip->reg_lock, flags);
  202. snd_es1688_mixer_write(chip, 0x40, cfg);
  203. spin_unlock_irqrestore(&chip->reg_lock, flags);
  204. /* --- */
  205. spin_lock_irqsave(&chip->reg_lock, flags);
  206. snd_es1688_read(chip, 0xb1);
  207. snd_es1688_read(chip, 0xb2);
  208. spin_unlock_irqrestore(&chip->reg_lock, flags);
  209. if (enable) {
  210. cfg = 0xf0; /* enable only DMA counter interrupt */
  211. irq_bits = irqs[chip->irq & 0x0f];
  212. if (irq_bits < 0) {
  213. snd_printk("[0x%lx] ESS: bad IRQ %d for ES1688 chip!!\n", chip->port, chip->irq);
  214. #if 0
  215. irq_bits = 0;
  216. cfg = 0x10;
  217. #endif
  218. return -EINVAL;
  219. }
  220. spin_lock_irqsave(&chip->reg_lock, flags);
  221. snd_es1688_write(chip, 0xb1, cfg | (irq_bits << 2));
  222. spin_unlock_irqrestore(&chip->reg_lock, flags);
  223. cfg = 0xf0; /* extended mode DMA enable */
  224. dma = chip->dma8;
  225. if (dma > 3 || dma == 2) {
  226. snd_printk("[0x%lx] ESS: bad DMA channel %d for ES1688 chip!!\n", chip->port, dma);
  227. #if 0
  228. dma_bits = 0;
  229. cfg = 0x00; /* disable all DMA */
  230. #endif
  231. return -EINVAL;
  232. } else {
  233. dma_bits = dma;
  234. if (dma != 3)
  235. dma_bits++;
  236. }
  237. spin_lock_irqsave(&chip->reg_lock, flags);
  238. snd_es1688_write(chip, 0xb2, cfg | (dma_bits << 2));
  239. spin_unlock_irqrestore(&chip->reg_lock, flags);
  240. } else {
  241. spin_lock_irqsave(&chip->reg_lock, flags);
  242. snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */
  243. snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */
  244. spin_unlock_irqrestore(&chip->reg_lock, flags);
  245. }
  246. spin_lock_irqsave(&chip->reg_lock, flags);
  247. snd_es1688_read(chip, 0xb1);
  248. snd_es1688_read(chip, 0xb2);
  249. snd_es1688_reset(chip);
  250. spin_unlock_irqrestore(&chip->reg_lock, flags);
  251. return 0;
  252. }
  253. /*
  254. */
  255. static ratnum_t clocks[2] = {
  256. {
  257. .num = 795444,
  258. .den_min = 1,
  259. .den_max = 128,
  260. .den_step = 1,
  261. },
  262. {
  263. .num = 397722,
  264. .den_min = 1,
  265. .den_max = 128,
  266. .den_step = 1,
  267. }
  268. };
  269. static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
  270. .nrats = 2,
  271. .rats = clocks,
  272. };
  273. static void snd_es1688_set_rate(es1688_t *chip, snd_pcm_substream_t *substream)
  274. {
  275. snd_pcm_runtime_t *runtime = substream->runtime;
  276. unsigned int bits, divider;
  277. if (runtime->rate_num == clocks[0].num)
  278. bits = 256 - runtime->rate_den;
  279. else
  280. bits = 128 - runtime->rate_den;
  281. /* set filter register */
  282. divider = 256 - 7160000*20/(8*82*runtime->rate);
  283. /* write result to hardware */
  284. snd_es1688_write(chip, 0xa1, bits);
  285. snd_es1688_write(chip, 0xa2, divider);
  286. }
  287. static int snd_es1688_ioctl(snd_pcm_substream_t * substream,
  288. unsigned int cmd, void *arg)
  289. {
  290. return snd_pcm_lib_ioctl(substream, cmd, arg);
  291. }
  292. static int snd_es1688_trigger(es1688_t *chip, int cmd, unsigned char value)
  293. {
  294. int val;
  295. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  296. value = 0x00;
  297. } else if (cmd != SNDRV_PCM_TRIGGER_START) {
  298. return -EINVAL;
  299. }
  300. spin_lock(&chip->reg_lock);
  301. chip->trigger_value = value;
  302. val = snd_es1688_read(chip, 0xb8);
  303. if ((val < 0) || (val & 0x0f) == value) {
  304. spin_unlock(&chip->reg_lock);
  305. return -EINVAL; /* something is wrong */
  306. }
  307. #if 0
  308. printk("trigger: val = 0x%x, value = 0x%x\n", val, value);
  309. printk("trigger: pointer = 0x%x\n", snd_dma_pointer(chip->dma8, chip->dma_size));
  310. #endif
  311. snd_es1688_write(chip, 0xb8, (val & 0xf0) | value);
  312. spin_unlock(&chip->reg_lock);
  313. return 0;
  314. }
  315. static int snd_es1688_hw_params(snd_pcm_substream_t * substream,
  316. snd_pcm_hw_params_t * hw_params)
  317. {
  318. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  319. }
  320. static int snd_es1688_hw_free(snd_pcm_substream_t * substream)
  321. {
  322. return snd_pcm_lib_free_pages(substream);
  323. }
  324. static int snd_es1688_playback_prepare(snd_pcm_substream_t * substream)
  325. {
  326. unsigned long flags;
  327. es1688_t *chip = snd_pcm_substream_chip(substream);
  328. snd_pcm_runtime_t *runtime = substream->runtime;
  329. unsigned int size = snd_pcm_lib_buffer_bytes(substream);
  330. unsigned int count = snd_pcm_lib_period_bytes(substream);
  331. chip->dma_size = size;
  332. spin_lock_irqsave(&chip->reg_lock, flags);
  333. snd_es1688_reset(chip);
  334. snd_es1688_set_rate(chip, substream);
  335. snd_es1688_write(chip, 0xb8, 4); /* auto init DMA mode */
  336. snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels));
  337. snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */
  338. if (runtime->channels == 1) {
  339. if (snd_pcm_format_width(runtime->format) == 8) {
  340. /* 8. bit mono */
  341. snd_es1688_write(chip, 0xb6, 0x80);
  342. snd_es1688_write(chip, 0xb7, 0x51);
  343. snd_es1688_write(chip, 0xb7, 0xd0);
  344. } else {
  345. /* 16. bit mono */
  346. snd_es1688_write(chip, 0xb6, 0x00);
  347. snd_es1688_write(chip, 0xb7, 0x71);
  348. snd_es1688_write(chip, 0xb7, 0xf4);
  349. }
  350. } else {
  351. if (snd_pcm_format_width(runtime->format) == 8) {
  352. /* 8. bit stereo */
  353. snd_es1688_write(chip, 0xb6, 0x80);
  354. snd_es1688_write(chip, 0xb7, 0x51);
  355. snd_es1688_write(chip, 0xb7, 0x98);
  356. } else {
  357. /* 16. bit stereo */
  358. snd_es1688_write(chip, 0xb6, 0x00);
  359. snd_es1688_write(chip, 0xb7, 0x71);
  360. snd_es1688_write(chip, 0xb7, 0xbc);
  361. }
  362. }
  363. snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
  364. snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
  365. snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKON);
  366. spin_unlock_irqrestore(&chip->reg_lock, flags);
  367. /* --- */
  368. count = -count;
  369. snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
  370. spin_lock_irqsave(&chip->reg_lock, flags);
  371. snd_es1688_write(chip, 0xa4, (unsigned char) count);
  372. snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8));
  373. spin_unlock_irqrestore(&chip->reg_lock, flags);
  374. return 0;
  375. }
  376. static int snd_es1688_playback_trigger(snd_pcm_substream_t * substream,
  377. int cmd)
  378. {
  379. es1688_t *chip = snd_pcm_substream_chip(substream);
  380. return snd_es1688_trigger(chip, cmd, 0x05);
  381. }
  382. static int snd_es1688_capture_prepare(snd_pcm_substream_t * substream)
  383. {
  384. unsigned long flags;
  385. es1688_t *chip = snd_pcm_substream_chip(substream);
  386. snd_pcm_runtime_t *runtime = substream->runtime;
  387. unsigned int size = snd_pcm_lib_buffer_bytes(substream);
  388. unsigned int count = snd_pcm_lib_period_bytes(substream);
  389. chip->dma_size = size;
  390. spin_lock_irqsave(&chip->reg_lock, flags);
  391. snd_es1688_reset(chip);
  392. snd_es1688_set_rate(chip, substream);
  393. snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKOFF);
  394. snd_es1688_write(chip, 0xb8, 0x0e); /* auto init DMA mode */
  395. snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels));
  396. snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */
  397. if (runtime->channels == 1) {
  398. if (snd_pcm_format_width(runtime->format) == 8) {
  399. /* 8. bit mono */
  400. snd_es1688_write(chip, 0xb7, 0x51);
  401. snd_es1688_write(chip, 0xb7, 0xd0);
  402. } else {
  403. /* 16. bit mono */
  404. snd_es1688_write(chip, 0xb7, 0x71);
  405. snd_es1688_write(chip, 0xb7, 0xf4);
  406. }
  407. } else {
  408. if (snd_pcm_format_width(runtime->format) == 8) {
  409. /* 8. bit stereo */
  410. snd_es1688_write(chip, 0xb7, 0x51);
  411. snd_es1688_write(chip, 0xb7, 0x98);
  412. } else {
  413. /* 16. bit stereo */
  414. snd_es1688_write(chip, 0xb7, 0x71);
  415. snd_es1688_write(chip, 0xb7, 0xbc);
  416. }
  417. }
  418. snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
  419. snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
  420. spin_unlock_irqrestore(&chip->reg_lock, flags);
  421. /* --- */
  422. count = -count;
  423. snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
  424. spin_lock_irqsave(&chip->reg_lock, flags);
  425. snd_es1688_write(chip, 0xa4, (unsigned char) count);
  426. snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8));
  427. spin_unlock_irqrestore(&chip->reg_lock, flags);
  428. return 0;
  429. }
  430. static int snd_es1688_capture_trigger(snd_pcm_substream_t * substream,
  431. int cmd)
  432. {
  433. es1688_t *chip = snd_pcm_substream_chip(substream);
  434. return snd_es1688_trigger(chip, cmd, 0x0f);
  435. }
  436. static irqreturn_t snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  437. {
  438. es1688_t *chip = dev_id;
  439. if (chip->trigger_value == 0x05) /* ok.. playback is active */
  440. snd_pcm_period_elapsed(chip->playback_substream);
  441. if (chip->trigger_value == 0x0f) /* ok.. capture is active */
  442. snd_pcm_period_elapsed(chip->capture_substream);
  443. inb(ES1688P(chip, DATA_AVAIL)); /* ack interrupt */
  444. return IRQ_HANDLED;
  445. }
  446. static snd_pcm_uframes_t snd_es1688_playback_pointer(snd_pcm_substream_t * substream)
  447. {
  448. es1688_t *chip = snd_pcm_substream_chip(substream);
  449. size_t ptr;
  450. if (chip->trigger_value != 0x05)
  451. return 0;
  452. ptr = snd_dma_pointer(chip->dma8, chip->dma_size);
  453. return bytes_to_frames(substream->runtime, ptr);
  454. }
  455. static snd_pcm_uframes_t snd_es1688_capture_pointer(snd_pcm_substream_t * substream)
  456. {
  457. es1688_t *chip = snd_pcm_substream_chip(substream);
  458. size_t ptr;
  459. if (chip->trigger_value != 0x0f)
  460. return 0;
  461. ptr = snd_dma_pointer(chip->dma8, chip->dma_size);
  462. return bytes_to_frames(substream->runtime, ptr);
  463. }
  464. /*
  465. */
  466. static snd_pcm_hardware_t snd_es1688_playback =
  467. {
  468. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  469. SNDRV_PCM_INFO_MMAP_VALID),
  470. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  471. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  472. .rate_min = 4000,
  473. .rate_max = 48000,
  474. .channels_min = 1,
  475. .channels_max = 2,
  476. .buffer_bytes_max = 65536,
  477. .period_bytes_min = 64,
  478. .period_bytes_max = 65536,
  479. .periods_min = 1,
  480. .periods_max = 1024,
  481. .fifo_size = 0,
  482. };
  483. static snd_pcm_hardware_t snd_es1688_capture =
  484. {
  485. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  486. SNDRV_PCM_INFO_MMAP_VALID),
  487. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  488. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  489. .rate_min = 4000,
  490. .rate_max = 48000,
  491. .channels_min = 1,
  492. .channels_max = 2,
  493. .buffer_bytes_max = 65536,
  494. .period_bytes_min = 64,
  495. .period_bytes_max = 65536,
  496. .periods_min = 1,
  497. .periods_max = 1024,
  498. .fifo_size = 0,
  499. };
  500. /*
  501. */
  502. static int snd_es1688_playback_open(snd_pcm_substream_t * substream)
  503. {
  504. es1688_t *chip = snd_pcm_substream_chip(substream);
  505. snd_pcm_runtime_t *runtime = substream->runtime;
  506. if (chip->capture_substream != NULL)
  507. return -EAGAIN;
  508. chip->playback_substream = substream;
  509. runtime->hw = snd_es1688_playback;
  510. snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  511. &hw_constraints_clocks);
  512. return 0;
  513. }
  514. static int snd_es1688_capture_open(snd_pcm_substream_t * substream)
  515. {
  516. es1688_t *chip = snd_pcm_substream_chip(substream);
  517. snd_pcm_runtime_t *runtime = substream->runtime;
  518. if (chip->playback_substream != NULL)
  519. return -EAGAIN;
  520. chip->capture_substream = substream;
  521. runtime->hw = snd_es1688_capture;
  522. snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  523. &hw_constraints_clocks);
  524. return 0;
  525. }
  526. static int snd_es1688_playback_close(snd_pcm_substream_t * substream)
  527. {
  528. es1688_t *chip = snd_pcm_substream_chip(substream);
  529. chip->playback_substream = NULL;
  530. return 0;
  531. }
  532. static int snd_es1688_capture_close(snd_pcm_substream_t * substream)
  533. {
  534. es1688_t *chip = snd_pcm_substream_chip(substream);
  535. chip->capture_substream = NULL;
  536. return 0;
  537. }
  538. static int snd_es1688_free(es1688_t *chip)
  539. {
  540. if (chip->res_port) {
  541. snd_es1688_init(chip, 0);
  542. release_and_free_resource(chip->res_port);
  543. }
  544. if (chip->irq >= 0)
  545. free_irq(chip->irq, (void *) chip);
  546. if (chip->dma8 >= 0) {
  547. disable_dma(chip->dma8);
  548. free_dma(chip->dma8);
  549. }
  550. kfree(chip);
  551. return 0;
  552. }
  553. static int snd_es1688_dev_free(snd_device_t *device)
  554. {
  555. es1688_t *chip = device->device_data;
  556. return snd_es1688_free(chip);
  557. }
  558. static const char *snd_es1688_chip_id(es1688_t *chip)
  559. {
  560. static char tmp[16];
  561. sprintf(tmp, "ES%s688 rev %i", chip->hardware == ES1688_HW_688 ? "" : "1", chip->version & 0x0f);
  562. return tmp;
  563. }
  564. int snd_es1688_create(snd_card_t * card,
  565. unsigned long port,
  566. unsigned long mpu_port,
  567. int irq,
  568. int mpu_irq,
  569. int dma8,
  570. unsigned short hardware,
  571. es1688_t **rchip)
  572. {
  573. static snd_device_ops_t ops = {
  574. .dev_free = snd_es1688_dev_free,
  575. };
  576. es1688_t *chip;
  577. int err;
  578. *rchip = NULL;
  579. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  580. if (chip == NULL)
  581. return -ENOMEM;
  582. chip->irq = -1;
  583. chip->dma8 = -1;
  584. if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) {
  585. snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4);
  586. snd_es1688_free(chip);
  587. return -EBUSY;
  588. }
  589. if (request_irq(irq, snd_es1688_interrupt, SA_INTERRUPT, "ES1688", (void *) chip)) {
  590. snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq);
  591. snd_es1688_free(chip);
  592. return -EBUSY;
  593. }
  594. chip->irq = irq;
  595. if (request_dma(dma8, "ES1688")) {
  596. snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8);
  597. snd_es1688_free(chip);
  598. return -EBUSY;
  599. }
  600. chip->dma8 = dma8;
  601. spin_lock_init(&chip->reg_lock);
  602. spin_lock_init(&chip->mixer_lock);
  603. chip->card = card;
  604. chip->port = port;
  605. mpu_port &= ~0x000f;
  606. if (mpu_port < 0x300 || mpu_port > 0x330)
  607. mpu_port = 0;
  608. chip->mpu_port = mpu_port;
  609. chip->mpu_irq = mpu_irq;
  610. chip->hardware = hardware;
  611. if ((err = snd_es1688_probe(chip)) < 0) {
  612. snd_es1688_free(chip);
  613. return err;
  614. }
  615. if ((err = snd_es1688_init(chip, 1)) < 0) {
  616. snd_es1688_free(chip);
  617. return err;
  618. }
  619. /* Register device */
  620. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  621. snd_es1688_free(chip);
  622. return err;
  623. }
  624. *rchip = chip;
  625. return 0;
  626. }
  627. static snd_pcm_ops_t snd_es1688_playback_ops = {
  628. .open = snd_es1688_playback_open,
  629. .close = snd_es1688_playback_close,
  630. .ioctl = snd_es1688_ioctl,
  631. .hw_params = snd_es1688_hw_params,
  632. .hw_free = snd_es1688_hw_free,
  633. .prepare = snd_es1688_playback_prepare,
  634. .trigger = snd_es1688_playback_trigger,
  635. .pointer = snd_es1688_playback_pointer,
  636. };
  637. static snd_pcm_ops_t snd_es1688_capture_ops = {
  638. .open = snd_es1688_capture_open,
  639. .close = snd_es1688_capture_close,
  640. .ioctl = snd_es1688_ioctl,
  641. .hw_params = snd_es1688_hw_params,
  642. .hw_free = snd_es1688_hw_free,
  643. .prepare = snd_es1688_capture_prepare,
  644. .trigger = snd_es1688_capture_trigger,
  645. .pointer = snd_es1688_capture_pointer,
  646. };
  647. static void snd_es1688_pcm_free(snd_pcm_t *pcm)
  648. {
  649. es1688_t *chip = pcm->private_data;
  650. chip->pcm = NULL;
  651. snd_pcm_lib_preallocate_free_for_all(pcm);
  652. }
  653. int snd_es1688_pcm(es1688_t * chip, int device, snd_pcm_t ** rpcm)
  654. {
  655. snd_pcm_t *pcm;
  656. int err;
  657. if ((err = snd_pcm_new(chip->card, "ESx688", device, 1, 1, &pcm)) < 0)
  658. return err;
  659. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops);
  660. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1688_capture_ops);
  661. pcm->private_data = chip;
  662. pcm->private_free = snd_es1688_pcm_free;
  663. pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
  664. sprintf(pcm->name, snd_es1688_chip_id(chip));
  665. chip->pcm = pcm;
  666. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  667. snd_dma_isa_data(),
  668. 64*1024, 64*1024);
  669. if (rpcm)
  670. *rpcm = pcm;
  671. return 0;
  672. }
  673. /*
  674. * MIXER part
  675. */
  676. static int snd_es1688_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  677. {
  678. static char *texts[9] = {
  679. "Mic", "Mic Master", "CD", "AOUT",
  680. "Mic1", "Mix", "Line", "Master"
  681. };
  682. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  683. uinfo->count = 1;
  684. uinfo->value.enumerated.items = 8;
  685. if (uinfo->value.enumerated.item > 7)
  686. uinfo->value.enumerated.item = 7;
  687. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  688. return 0;
  689. }
  690. static int snd_es1688_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  691. {
  692. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  693. ucontrol->value.enumerated.item[0] = snd_es1688_mixer_read(chip, ES1688_REC_DEV) & 7;
  694. return 0;
  695. }
  696. static int snd_es1688_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  697. {
  698. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  699. unsigned long flags;
  700. unsigned char oval, nval;
  701. int change;
  702. if (ucontrol->value.enumerated.item[0] > 8)
  703. return -EINVAL;
  704. spin_lock_irqsave(&chip->reg_lock, flags);
  705. oval = snd_es1688_mixer_read(chip, ES1688_REC_DEV);
  706. nval = (ucontrol->value.enumerated.item[0] & 7) | (oval & ~15);
  707. change = nval != oval;
  708. if (change)
  709. snd_es1688_mixer_write(chip, ES1688_REC_DEV, nval);
  710. spin_unlock_irqrestore(&chip->reg_lock, flags);
  711. return change;
  712. }
  713. #define ES1688_SINGLE(xname, xindex, reg, shift, mask, invert) \
  714. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  715. .info = snd_es1688_info_single, \
  716. .get = snd_es1688_get_single, .put = snd_es1688_put_single, \
  717. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  718. static int snd_es1688_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  719. {
  720. int mask = (kcontrol->private_value >> 16) & 0xff;
  721. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  722. uinfo->count = 1;
  723. uinfo->value.integer.min = 0;
  724. uinfo->value.integer.max = mask;
  725. return 0;
  726. }
  727. static int snd_es1688_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  728. {
  729. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  730. unsigned long flags;
  731. int reg = kcontrol->private_value & 0xff;
  732. int shift = (kcontrol->private_value >> 8) & 0xff;
  733. int mask = (kcontrol->private_value >> 16) & 0xff;
  734. int invert = (kcontrol->private_value >> 24) & 0xff;
  735. spin_lock_irqsave(&chip->reg_lock, flags);
  736. ucontrol->value.integer.value[0] = (snd_es1688_mixer_read(chip, reg) >> shift) & mask;
  737. spin_unlock_irqrestore(&chip->reg_lock, flags);
  738. if (invert)
  739. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  740. return 0;
  741. }
  742. static int snd_es1688_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  743. {
  744. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  745. unsigned long flags;
  746. int reg = kcontrol->private_value & 0xff;
  747. int shift = (kcontrol->private_value >> 8) & 0xff;
  748. int mask = (kcontrol->private_value >> 16) & 0xff;
  749. int invert = (kcontrol->private_value >> 24) & 0xff;
  750. int change;
  751. unsigned char oval, nval;
  752. nval = (ucontrol->value.integer.value[0] & mask);
  753. if (invert)
  754. nval = mask - nval;
  755. nval <<= shift;
  756. spin_lock_irqsave(&chip->reg_lock, flags);
  757. oval = snd_es1688_mixer_read(chip, reg);
  758. nval = (oval & ~(mask << shift)) | nval;
  759. change = nval != oval;
  760. if (change)
  761. snd_es1688_mixer_write(chip, reg, nval);
  762. spin_unlock_irqrestore(&chip->reg_lock, flags);
  763. return change;
  764. }
  765. #define ES1688_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  766. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  767. .info = snd_es1688_info_double, \
  768. .get = snd_es1688_get_double, .put = snd_es1688_put_double, \
  769. .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
  770. static int snd_es1688_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  771. {
  772. int mask = (kcontrol->private_value >> 24) & 0xff;
  773. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  774. uinfo->count = 2;
  775. uinfo->value.integer.min = 0;
  776. uinfo->value.integer.max = mask;
  777. return 0;
  778. }
  779. static int snd_es1688_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  780. {
  781. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  782. unsigned long flags;
  783. int left_reg = kcontrol->private_value & 0xff;
  784. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  785. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  786. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  787. int mask = (kcontrol->private_value >> 24) & 0xff;
  788. int invert = (kcontrol->private_value >> 22) & 1;
  789. unsigned char left, right;
  790. spin_lock_irqsave(&chip->reg_lock, flags);
  791. if (left_reg < 0xa0)
  792. left = snd_es1688_mixer_read(chip, left_reg);
  793. else
  794. left = snd_es1688_read(chip, left_reg);
  795. if (left_reg != right_reg) {
  796. if (right_reg < 0xa0)
  797. right = snd_es1688_mixer_read(chip, right_reg);
  798. else
  799. right = snd_es1688_read(chip, right_reg);
  800. } else
  801. right = left;
  802. spin_unlock_irqrestore(&chip->reg_lock, flags);
  803. ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
  804. ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
  805. if (invert) {
  806. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  807. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  808. }
  809. return 0;
  810. }
  811. static int snd_es1688_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  812. {
  813. es1688_t *chip = snd_kcontrol_chip(kcontrol);
  814. unsigned long flags;
  815. int left_reg = kcontrol->private_value & 0xff;
  816. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  817. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  818. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  819. int mask = (kcontrol->private_value >> 24) & 0xff;
  820. int invert = (kcontrol->private_value >> 22) & 1;
  821. int change;
  822. unsigned char val1, val2, oval1, oval2;
  823. val1 = ucontrol->value.integer.value[0] & mask;
  824. val2 = ucontrol->value.integer.value[1] & mask;
  825. if (invert) {
  826. val1 = mask - val1;
  827. val2 = mask - val2;
  828. }
  829. val1 <<= shift_left;
  830. val2 <<= shift_right;
  831. spin_lock_irqsave(&chip->reg_lock, flags);
  832. if (left_reg != right_reg) {
  833. if (left_reg < 0xa0)
  834. oval1 = snd_es1688_mixer_read(chip, left_reg);
  835. else
  836. oval1 = snd_es1688_read(chip, left_reg);
  837. if (right_reg < 0xa0)
  838. oval2 = snd_es1688_mixer_read(chip, right_reg);
  839. else
  840. oval2 = snd_es1688_read(chip, right_reg);
  841. val1 = (oval1 & ~(mask << shift_left)) | val1;
  842. val2 = (oval2 & ~(mask << shift_right)) | val2;
  843. change = val1 != oval1 || val2 != oval2;
  844. if (change) {
  845. if (left_reg < 0xa0)
  846. snd_es1688_mixer_write(chip, left_reg, val1);
  847. else
  848. snd_es1688_write(chip, left_reg, val1);
  849. if (right_reg < 0xa0)
  850. snd_es1688_mixer_write(chip, right_reg, val1);
  851. else
  852. snd_es1688_write(chip, right_reg, val1);
  853. }
  854. } else {
  855. if (left_reg < 0xa0)
  856. oval1 = snd_es1688_mixer_read(chip, left_reg);
  857. else
  858. oval1 = snd_es1688_read(chip, left_reg);
  859. val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
  860. change = val1 != oval1;
  861. if (change) {
  862. if (left_reg < 0xa0)
  863. snd_es1688_mixer_write(chip, left_reg, val1);
  864. else
  865. snd_es1688_write(chip, left_reg, val1);
  866. }
  867. }
  868. spin_unlock_irqrestore(&chip->reg_lock, flags);
  869. return change;
  870. }
  871. static snd_kcontrol_new_t snd_es1688_controls[] = {
  872. ES1688_DOUBLE("Master Playback Volume", 0, ES1688_MASTER_DEV, ES1688_MASTER_DEV, 4, 0, 15, 0),
  873. ES1688_DOUBLE("PCM Playback Volume", 0, ES1688_PCM_DEV, ES1688_PCM_DEV, 4, 0, 15, 0),
  874. ES1688_DOUBLE("Line Playback Volume", 0, ES1688_LINE_DEV, ES1688_LINE_DEV, 4, 0, 15, 0),
  875. ES1688_DOUBLE("CD Playback Volume", 0, ES1688_CD_DEV, ES1688_CD_DEV, 4, 0, 15, 0),
  876. ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0),
  877. ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0),
  878. ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0),
  879. ES1688_SINGLE("PC Speaker Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0),
  880. ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0),
  881. ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1),
  882. {
  883. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  884. .name = "Capture Source",
  885. .info = snd_es1688_info_mux,
  886. .get = snd_es1688_get_mux,
  887. .put = snd_es1688_put_mux,
  888. },
  889. };
  890. #define ES1688_INIT_TABLE_SIZE (sizeof(snd_es1688_init_table)/2)
  891. static unsigned char snd_es1688_init_table[][2] = {
  892. { ES1688_MASTER_DEV, 0 },
  893. { ES1688_PCM_DEV, 0 },
  894. { ES1688_LINE_DEV, 0 },
  895. { ES1688_CD_DEV, 0 },
  896. { ES1688_FM_DEV, 0 },
  897. { ES1688_MIC_DEV, 0 },
  898. { ES1688_AUX_DEV, 0 },
  899. { ES1688_SPEAKER_DEV, 0 },
  900. { ES1688_RECLEV_DEV, 0 },
  901. { ES1688_REC_DEV, 0x17 }
  902. };
  903. int snd_es1688_mixer(es1688_t *chip)
  904. {
  905. snd_card_t *card;
  906. unsigned int idx;
  907. int err;
  908. unsigned char reg, val;
  909. snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
  910. card = chip->card;
  911. strcpy(card->mixername, snd_es1688_chip_id(chip));
  912. for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) {
  913. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es1688_controls[idx], chip))) < 0)
  914. return err;
  915. }
  916. for (idx = 0; idx < ES1688_INIT_TABLE_SIZE; idx++) {
  917. reg = snd_es1688_init_table[idx][0];
  918. val = snd_es1688_init_table[idx][1];
  919. if (reg < 0xa0)
  920. snd_es1688_mixer_write(chip, reg, val);
  921. else
  922. snd_es1688_write(chip, reg, val);
  923. }
  924. return 0;
  925. }
  926. EXPORT_SYMBOL(snd_es1688_mixer_write);
  927. EXPORT_SYMBOL(snd_es1688_create);
  928. EXPORT_SYMBOL(snd_es1688_pcm);
  929. EXPORT_SYMBOL(snd_es1688_mixer);
  930. /*
  931. * INIT part
  932. */
  933. static int __init alsa_es1688_init(void)
  934. {
  935. return 0;
  936. }
  937. static void __exit alsa_es1688_exit(void)
  938. {
  939. }
  940. module_init(alsa_es1688_init)
  941. module_exit(alsa_es1688_exit)