lx_core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. /* -*- linux-c -*- *
  2. *
  3. * ALSA driver for the digigram lx6464es interface
  4. * low-level interface
  5. *
  6. * Copyright (c) 2009 Tim Blechmann <tim@klingt.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, write to
  20. * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. /* #define RMH_DEBUG 1 */
  25. #include <linux/module.h>
  26. #include <linux/pci.h>
  27. #include <linux/delay.h>
  28. #include "lx6464es.h"
  29. #include "lx_core.h"
  30. /* low-level register access */
  31. static const unsigned long dsp_port_offsets[] = {
  32. 0,
  33. 0x400,
  34. 0x401,
  35. 0x402,
  36. 0x403,
  37. 0x404,
  38. 0x405,
  39. 0x406,
  40. 0x407,
  41. 0x408,
  42. 0x409,
  43. 0x40a,
  44. 0x40b,
  45. 0x40c,
  46. 0x410,
  47. 0x411,
  48. 0x412,
  49. 0x413,
  50. 0x414,
  51. 0x415,
  52. 0x416,
  53. 0x420,
  54. 0x430,
  55. 0x431,
  56. 0x432,
  57. 0x433,
  58. 0x434,
  59. 0x440
  60. };
  61. static void __iomem *lx_dsp_register(struct lx6464es *chip, int port)
  62. {
  63. void __iomem *base_address = chip->port_dsp_bar;
  64. return base_address + dsp_port_offsets[port]*4;
  65. }
  66. unsigned long lx_dsp_reg_read(struct lx6464es *chip, int port)
  67. {
  68. void __iomem *address = lx_dsp_register(chip, port);
  69. return ioread32(address);
  70. }
  71. void lx_dsp_reg_readbuf(struct lx6464es *chip, int port, u32 *data, u32 len)
  72. {
  73. void __iomem *address = lx_dsp_register(chip, port);
  74. memcpy_fromio(data, address, len*sizeof(u32));
  75. }
  76. void lx_dsp_reg_write(struct lx6464es *chip, int port, unsigned data)
  77. {
  78. void __iomem *address = lx_dsp_register(chip, port);
  79. iowrite32(data, address);
  80. }
  81. void lx_dsp_reg_writebuf(struct lx6464es *chip, int port, const u32 *data,
  82. u32 len)
  83. {
  84. void __iomem *address = lx_dsp_register(chip, port);
  85. memcpy_toio(address, data, len*sizeof(u32));
  86. }
  87. static const unsigned long plx_port_offsets[] = {
  88. 0x04,
  89. 0x40,
  90. 0x44,
  91. 0x48,
  92. 0x4c,
  93. 0x50,
  94. 0x54,
  95. 0x58,
  96. 0x5c,
  97. 0x64,
  98. 0x68,
  99. 0x6C
  100. };
  101. static void __iomem *lx_plx_register(struct lx6464es *chip, int port)
  102. {
  103. void __iomem *base_address = chip->port_plx_remapped;
  104. return base_address + plx_port_offsets[port];
  105. }
  106. unsigned long lx_plx_reg_read(struct lx6464es *chip, int port)
  107. {
  108. void __iomem *address = lx_plx_register(chip, port);
  109. return ioread32(address);
  110. }
  111. void lx_plx_reg_write(struct lx6464es *chip, int port, u32 data)
  112. {
  113. void __iomem *address = lx_plx_register(chip, port);
  114. iowrite32(data, address);
  115. }
  116. u32 lx_plx_mbox_read(struct lx6464es *chip, int mbox_nr)
  117. {
  118. int index;
  119. switch (mbox_nr) {
  120. case 1:
  121. index = ePLX_MBOX1; break;
  122. case 2:
  123. index = ePLX_MBOX2; break;
  124. case 3:
  125. index = ePLX_MBOX3; break;
  126. case 4:
  127. index = ePLX_MBOX4; break;
  128. case 5:
  129. index = ePLX_MBOX5; break;
  130. case 6:
  131. index = ePLX_MBOX6; break;
  132. case 7:
  133. index = ePLX_MBOX7; break;
  134. case 0: /* reserved for HF flags */
  135. snd_BUG();
  136. default:
  137. return 0xdeadbeef;
  138. }
  139. return lx_plx_reg_read(chip, index);
  140. }
  141. int lx_plx_mbox_write(struct lx6464es *chip, int mbox_nr, u32 value)
  142. {
  143. int index = -1;
  144. switch (mbox_nr) {
  145. case 1:
  146. index = ePLX_MBOX1; break;
  147. case 3:
  148. index = ePLX_MBOX3; break;
  149. case 4:
  150. index = ePLX_MBOX4; break;
  151. case 5:
  152. index = ePLX_MBOX5; break;
  153. case 6:
  154. index = ePLX_MBOX6; break;
  155. case 7:
  156. index = ePLX_MBOX7; break;
  157. case 0: /* reserved for HF flags */
  158. case 2: /* reserved for Pipe States
  159. * the DSP keeps an image of it */
  160. snd_BUG();
  161. return -EBADRQC;
  162. }
  163. lx_plx_reg_write(chip, index, value);
  164. return 0;
  165. }
  166. /* rmh */
  167. #ifdef CONFIG_SND_DEBUG
  168. #define CMD_NAME(a) a
  169. #else
  170. #define CMD_NAME(a) NULL
  171. #endif
  172. #define Reg_CSM_MR 0x00000002
  173. #define Reg_CSM_MC 0x00000001
  174. struct dsp_cmd_info {
  175. u32 dcCodeOp; /* Op Code of the command (usually 1st 24-bits
  176. * word).*/
  177. u16 dcCmdLength; /* Command length in words of 24 bits.*/
  178. u16 dcStatusType; /* Status type: 0 for fixed length, 1 for
  179. * random. */
  180. u16 dcStatusLength; /* Status length (if fixed).*/
  181. char *dcOpName;
  182. };
  183. /*
  184. Initialization and control data for the Microblaze interface
  185. - OpCode:
  186. the opcode field of the command set at the proper offset
  187. - CmdLength
  188. the number of command words
  189. - StatusType
  190. offset in the status registers: 0 means that the return value may be
  191. different from 0, and must be read
  192. - StatusLength
  193. the number of status words (in addition to the return value)
  194. */
  195. static struct dsp_cmd_info dsp_commands[] =
  196. {
  197. { (CMD_00_INFO_DEBUG << OPCODE_OFFSET) , 1 /*custom*/
  198. , 1 , 0 /**/ , CMD_NAME("INFO_DEBUG") },
  199. { (CMD_01_GET_SYS_CFG << OPCODE_OFFSET) , 1 /**/
  200. , 1 , 2 /**/ , CMD_NAME("GET_SYS_CFG") },
  201. { (CMD_02_SET_GRANULARITY << OPCODE_OFFSET) , 1 /**/
  202. , 1 , 0 /**/ , CMD_NAME("SET_GRANULARITY") },
  203. { (CMD_03_SET_TIMER_IRQ << OPCODE_OFFSET) , 1 /**/
  204. , 1 , 0 /**/ , CMD_NAME("SET_TIMER_IRQ") },
  205. { (CMD_04_GET_EVENT << OPCODE_OFFSET) , 1 /**/
  206. , 1 , 0 /*up to 10*/ , CMD_NAME("GET_EVENT") },
  207. { (CMD_05_GET_PIPES << OPCODE_OFFSET) , 1 /**/
  208. , 1 , 2 /*up to 4*/ , CMD_NAME("GET_PIPES") },
  209. { (CMD_06_ALLOCATE_PIPE << OPCODE_OFFSET) , 1 /**/
  210. , 0 , 0 /**/ , CMD_NAME("ALLOCATE_PIPE") },
  211. { (CMD_07_RELEASE_PIPE << OPCODE_OFFSET) , 1 /**/
  212. , 0 , 0 /**/ , CMD_NAME("RELEASE_PIPE") },
  213. { (CMD_08_ASK_BUFFERS << OPCODE_OFFSET) , 1 /**/
  214. , 1 , MAX_STREAM_BUFFER , CMD_NAME("ASK_BUFFERS") },
  215. { (CMD_09_STOP_PIPE << OPCODE_OFFSET) , 1 /**/
  216. , 0 , 0 /*up to 2*/ , CMD_NAME("STOP_PIPE") },
  217. { (CMD_0A_GET_PIPE_SPL_COUNT << OPCODE_OFFSET) , 1 /**/
  218. , 1 , 1 /*up to 2*/ , CMD_NAME("GET_PIPE_SPL_COUNT") },
  219. { (CMD_0B_TOGGLE_PIPE_STATE << OPCODE_OFFSET) , 1 /*up to 5*/
  220. , 1 , 0 /**/ , CMD_NAME("TOGGLE_PIPE_STATE") },
  221. { (CMD_0C_DEF_STREAM << OPCODE_OFFSET) , 1 /*up to 4*/
  222. , 1 , 0 /**/ , CMD_NAME("DEF_STREAM") },
  223. { (CMD_0D_SET_MUTE << OPCODE_OFFSET) , 3 /**/
  224. , 1 , 0 /**/ , CMD_NAME("SET_MUTE") },
  225. { (CMD_0E_GET_STREAM_SPL_COUNT << OPCODE_OFFSET) , 1/**/
  226. , 1 , 2 /**/ , CMD_NAME("GET_STREAM_SPL_COUNT") },
  227. { (CMD_0F_UPDATE_BUFFER << OPCODE_OFFSET) , 3 /*up to 4*/
  228. , 0 , 1 /**/ , CMD_NAME("UPDATE_BUFFER") },
  229. { (CMD_10_GET_BUFFER << OPCODE_OFFSET) , 1 /**/
  230. , 1 , 4 /**/ , CMD_NAME("GET_BUFFER") },
  231. { (CMD_11_CANCEL_BUFFER << OPCODE_OFFSET) , 1 /**/
  232. , 1 , 1 /*up to 4*/ , CMD_NAME("CANCEL_BUFFER") },
  233. { (CMD_12_GET_PEAK << OPCODE_OFFSET) , 1 /**/
  234. , 1 , 1 /**/ , CMD_NAME("GET_PEAK") },
  235. { (CMD_13_SET_STREAM_STATE << OPCODE_OFFSET) , 1 /**/
  236. , 1 , 0 /**/ , CMD_NAME("SET_STREAM_STATE") },
  237. };
  238. static void lx_message_init(struct lx_rmh *rmh, enum cmd_mb_opcodes cmd)
  239. {
  240. snd_BUG_ON(cmd >= CMD_14_INVALID);
  241. rmh->cmd[0] = dsp_commands[cmd].dcCodeOp;
  242. rmh->cmd_len = dsp_commands[cmd].dcCmdLength;
  243. rmh->stat_len = dsp_commands[cmd].dcStatusLength;
  244. rmh->dsp_stat = dsp_commands[cmd].dcStatusType;
  245. rmh->cmd_idx = cmd;
  246. memset(&rmh->cmd[1], 0, (REG_CRM_NUMBER - 1) * sizeof(u32));
  247. #ifdef CONFIG_SND_DEBUG
  248. memset(rmh->stat, 0, REG_CRM_NUMBER * sizeof(u32));
  249. #endif
  250. #ifdef RMH_DEBUG
  251. rmh->cmd_idx = cmd;
  252. #endif
  253. }
  254. #ifdef RMH_DEBUG
  255. #define LXRMH "lx6464es rmh: "
  256. static void lx_message_dump(struct lx_rmh *rmh)
  257. {
  258. u8 idx = rmh->cmd_idx;
  259. int i;
  260. snd_printk(LXRMH "command %s\n", dsp_commands[idx].dcOpName);
  261. for (i = 0; i != rmh->cmd_len; ++i)
  262. snd_printk(LXRMH "\tcmd[%d] %08x\n", i, rmh->cmd[i]);
  263. for (i = 0; i != rmh->stat_len; ++i)
  264. snd_printk(LXRMH "\tstat[%d]: %08x\n", i, rmh->stat[i]);
  265. snd_printk("\n");
  266. }
  267. #else
  268. static inline void lx_message_dump(struct lx_rmh *rmh)
  269. {}
  270. #endif
  271. /* sleep 500 - 100 = 400 times 100us -> the timeout is >= 40 ms */
  272. #define XILINX_TIMEOUT_MS 40
  273. #define XILINX_POLL_NO_SLEEP 100
  274. #define XILINX_POLL_ITERATIONS 150
  275. static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh)
  276. {
  277. u32 reg = ED_DSP_TIMED_OUT;
  278. int dwloop;
  279. if (lx_dsp_reg_read(chip, eReg_CSM) & (Reg_CSM_MC | Reg_CSM_MR)) {
  280. snd_printk(KERN_ERR LXP "PIOSendMessage eReg_CSM %x\n", reg);
  281. return -EBUSY;
  282. }
  283. /* write command */
  284. lx_dsp_reg_writebuf(chip, eReg_CRM1, rmh->cmd, rmh->cmd_len);
  285. /* MicoBlaze gogogo */
  286. lx_dsp_reg_write(chip, eReg_CSM, Reg_CSM_MC);
  287. /* wait for device to answer */
  288. for (dwloop = 0; dwloop != XILINX_TIMEOUT_MS * 1000; ++dwloop) {
  289. if (lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR) {
  290. if (rmh->dsp_stat == 0)
  291. reg = lx_dsp_reg_read(chip, eReg_CRM1);
  292. else
  293. reg = 0;
  294. goto polling_successful;
  295. } else
  296. udelay(1);
  297. }
  298. snd_printk(KERN_WARNING LXP "TIMEOUT lx_message_send_atomic! "
  299. "polling failed\n");
  300. polling_successful:
  301. if ((reg & ERROR_VALUE) == 0) {
  302. /* read response */
  303. if (rmh->stat_len) {
  304. snd_BUG_ON(rmh->stat_len >= (REG_CRM_NUMBER-1));
  305. lx_dsp_reg_readbuf(chip, eReg_CRM2, rmh->stat,
  306. rmh->stat_len);
  307. }
  308. } else
  309. snd_printk(LXP "rmh error: %08x\n", reg);
  310. /* clear Reg_CSM_MR */
  311. lx_dsp_reg_write(chip, eReg_CSM, 0);
  312. switch (reg) {
  313. case ED_DSP_TIMED_OUT:
  314. snd_printk(KERN_WARNING LXP "lx_message_send: dsp timeout\n");
  315. return -ETIMEDOUT;
  316. case ED_DSP_CRASHED:
  317. snd_printk(KERN_WARNING LXP "lx_message_send: dsp crashed\n");
  318. return -EAGAIN;
  319. }
  320. lx_message_dump(rmh);
  321. return reg;
  322. }
  323. /* low-level dsp access */
  324. int __devinit lx_dsp_get_version(struct lx6464es *chip, u32 *rdsp_version)
  325. {
  326. u16 ret;
  327. unsigned long flags;
  328. spin_lock_irqsave(&chip->msg_lock, flags);
  329. lx_message_init(&chip->rmh, CMD_01_GET_SYS_CFG);
  330. ret = lx_message_send_atomic(chip, &chip->rmh);
  331. *rdsp_version = chip->rmh.stat[1];
  332. spin_unlock_irqrestore(&chip->msg_lock, flags);
  333. return ret;
  334. }
  335. int lx_dsp_get_clock_frequency(struct lx6464es *chip, u32 *rfreq)
  336. {
  337. u16 ret = 0;
  338. unsigned long flags;
  339. u32 freq_raw = 0;
  340. u32 freq = 0;
  341. u32 frequency = 0;
  342. spin_lock_irqsave(&chip->msg_lock, flags);
  343. lx_message_init(&chip->rmh, CMD_01_GET_SYS_CFG);
  344. ret = lx_message_send_atomic(chip, &chip->rmh);
  345. if (ret == 0) {
  346. freq_raw = chip->rmh.stat[0] >> FREQ_FIELD_OFFSET;
  347. freq = freq_raw & XES_FREQ_COUNT8_MASK;
  348. if ((freq < XES_FREQ_COUNT8_48_MAX) ||
  349. (freq > XES_FREQ_COUNT8_44_MIN))
  350. frequency = 0; /* unknown */
  351. else if (freq >= XES_FREQ_COUNT8_44_MAX)
  352. frequency = 44100;
  353. else
  354. frequency = 48000;
  355. }
  356. spin_unlock_irqrestore(&chip->msg_lock, flags);
  357. *rfreq = frequency * chip->freq_ratio;
  358. return ret;
  359. }
  360. int lx_dsp_get_mac(struct lx6464es *chip, u8 *mac_address)
  361. {
  362. u32 macmsb, maclsb;
  363. macmsb = lx_dsp_reg_read(chip, eReg_ADMACESMSB) & 0x00FFFFFF;
  364. maclsb = lx_dsp_reg_read(chip, eReg_ADMACESLSB) & 0x00FFFFFF;
  365. /* todo: endianess handling */
  366. mac_address[5] = ((u8 *)(&maclsb))[0];
  367. mac_address[4] = ((u8 *)(&maclsb))[1];
  368. mac_address[3] = ((u8 *)(&maclsb))[2];
  369. mac_address[2] = ((u8 *)(&macmsb))[0];
  370. mac_address[1] = ((u8 *)(&macmsb))[1];
  371. mac_address[0] = ((u8 *)(&macmsb))[2];
  372. return 0;
  373. }
  374. int lx_dsp_set_granularity(struct lx6464es *chip, u32 gran)
  375. {
  376. unsigned long flags;
  377. int ret;
  378. spin_lock_irqsave(&chip->msg_lock, flags);
  379. lx_message_init(&chip->rmh, CMD_02_SET_GRANULARITY);
  380. chip->rmh.cmd[0] |= gran;
  381. ret = lx_message_send_atomic(chip, &chip->rmh);
  382. spin_unlock_irqrestore(&chip->msg_lock, flags);
  383. return ret;
  384. }
  385. int lx_dsp_read_async_events(struct lx6464es *chip, u32 *data)
  386. {
  387. unsigned long flags;
  388. int ret;
  389. spin_lock_irqsave(&chip->msg_lock, flags);
  390. lx_message_init(&chip->rmh, CMD_04_GET_EVENT);
  391. chip->rmh.stat_len = 9; /* we don't necessarily need the full length */
  392. ret = lx_message_send_atomic(chip, &chip->rmh);
  393. if (!ret)
  394. memcpy(data, chip->rmh.stat, chip->rmh.stat_len * sizeof(u32));
  395. spin_unlock_irqrestore(&chip->msg_lock, flags);
  396. return ret;
  397. }
  398. #define CSES_TIMEOUT 100 /* microseconds */
  399. #define CSES_CE 0x0001
  400. #define CSES_BROADCAST 0x0002
  401. #define CSES_UPDATE_LDSV 0x0004
  402. int lx_dsp_es_check_pipeline(struct lx6464es *chip)
  403. {
  404. int i;
  405. for (i = 0; i != CSES_TIMEOUT; ++i) {
  406. /*
  407. * le bit CSES_UPDATE_LDSV est à 1 dés que le macprog
  408. * est pret. il re-passe à 0 lorsque le premier read a
  409. * été fait. pour l'instant on retire le test car ce bit
  410. * passe a 1 environ 200 à 400 ms aprés que le registre
  411. * confES à été écrit (kick du xilinx ES).
  412. *
  413. * On ne teste que le bit CE.
  414. * */
  415. u32 cses = lx_dsp_reg_read(chip, eReg_CSES);
  416. if ((cses & CSES_CE) == 0)
  417. return 0;
  418. udelay(1);
  419. }
  420. return -ETIMEDOUT;
  421. }
  422. #define PIPE_INFO_TO_CMD(capture, pipe) \
  423. ((u32)((u32)(pipe) | ((capture) ? ID_IS_CAPTURE : 0L)) << ID_OFFSET)
  424. /* low-level pipe handling */
  425. int lx_pipe_allocate(struct lx6464es *chip, u32 pipe, int is_capture,
  426. int channels)
  427. {
  428. int err;
  429. unsigned long flags;
  430. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  431. spin_lock_irqsave(&chip->msg_lock, flags);
  432. lx_message_init(&chip->rmh, CMD_06_ALLOCATE_PIPE);
  433. chip->rmh.cmd[0] |= pipe_cmd;
  434. chip->rmh.cmd[0] |= channels;
  435. err = lx_message_send_atomic(chip, &chip->rmh);
  436. spin_unlock_irqrestore(&chip->msg_lock, flags);
  437. if (err != 0)
  438. snd_printk(KERN_ERR "lx6464es: could not allocate pipe\n");
  439. return err;
  440. }
  441. int lx_pipe_release(struct lx6464es *chip, u32 pipe, int is_capture)
  442. {
  443. int err;
  444. unsigned long flags;
  445. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  446. spin_lock_irqsave(&chip->msg_lock, flags);
  447. lx_message_init(&chip->rmh, CMD_07_RELEASE_PIPE);
  448. chip->rmh.cmd[0] |= pipe_cmd;
  449. err = lx_message_send_atomic(chip, &chip->rmh);
  450. spin_unlock_irqrestore(&chip->msg_lock, flags);
  451. return err;
  452. }
  453. int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture,
  454. u32 *r_needed, u32 *r_freed, u32 *size_array)
  455. {
  456. int err;
  457. unsigned long flags;
  458. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  459. #ifdef CONFIG_SND_DEBUG
  460. if (size_array)
  461. memset(size_array, 0, sizeof(u32)*MAX_STREAM_BUFFER);
  462. #endif
  463. *r_needed = 0;
  464. *r_freed = 0;
  465. spin_lock_irqsave(&chip->msg_lock, flags);
  466. lx_message_init(&chip->rmh, CMD_08_ASK_BUFFERS);
  467. chip->rmh.cmd[0] |= pipe_cmd;
  468. err = lx_message_send_atomic(chip, &chip->rmh);
  469. if (!err) {
  470. int i;
  471. for (i = 0; i < MAX_STREAM_BUFFER; ++i) {
  472. u32 stat = chip->rmh.stat[i];
  473. if (stat & (BF_EOB << BUFF_FLAGS_OFFSET)) {
  474. /* finished */
  475. *r_freed += 1;
  476. if (size_array)
  477. size_array[i] = stat & MASK_DATA_SIZE;
  478. } else if ((stat & (BF_VALID << BUFF_FLAGS_OFFSET))
  479. == 0)
  480. /* free */
  481. *r_needed += 1;
  482. }
  483. #if 0
  484. snd_printdd(LXP "CMD_08_ASK_BUFFERS: needed %d, freed %d\n",
  485. *r_needed, *r_freed);
  486. for (i = 0; i < MAX_STREAM_BUFFER; ++i) {
  487. for (i = 0; i != chip->rmh.stat_len; ++i)
  488. snd_printdd(" stat[%d]: %x, %x\n", i,
  489. chip->rmh.stat[i],
  490. chip->rmh.stat[i] & MASK_DATA_SIZE);
  491. }
  492. #endif
  493. }
  494. spin_unlock_irqrestore(&chip->msg_lock, flags);
  495. return err;
  496. }
  497. int lx_pipe_stop(struct lx6464es *chip, u32 pipe, int is_capture)
  498. {
  499. int err;
  500. unsigned long flags;
  501. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  502. spin_lock_irqsave(&chip->msg_lock, flags);
  503. lx_message_init(&chip->rmh, CMD_09_STOP_PIPE);
  504. chip->rmh.cmd[0] |= pipe_cmd;
  505. err = lx_message_send_atomic(chip, &chip->rmh);
  506. spin_unlock_irqrestore(&chip->msg_lock, flags);
  507. return err;
  508. }
  509. static int lx_pipe_toggle_state(struct lx6464es *chip, u32 pipe, int is_capture)
  510. {
  511. int err;
  512. unsigned long flags;
  513. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  514. spin_lock_irqsave(&chip->msg_lock, flags);
  515. lx_message_init(&chip->rmh, CMD_0B_TOGGLE_PIPE_STATE);
  516. chip->rmh.cmd[0] |= pipe_cmd;
  517. err = lx_message_send_atomic(chip, &chip->rmh);
  518. spin_unlock_irqrestore(&chip->msg_lock, flags);
  519. return err;
  520. }
  521. int lx_pipe_start(struct lx6464es *chip, u32 pipe, int is_capture)
  522. {
  523. int err;
  524. err = lx_pipe_wait_for_idle(chip, pipe, is_capture);
  525. if (err < 0)
  526. return err;
  527. err = lx_pipe_toggle_state(chip, pipe, is_capture);
  528. return err;
  529. }
  530. int lx_pipe_pause(struct lx6464es *chip, u32 pipe, int is_capture)
  531. {
  532. int err = 0;
  533. err = lx_pipe_wait_for_start(chip, pipe, is_capture);
  534. if (err < 0)
  535. return err;
  536. err = lx_pipe_toggle_state(chip, pipe, is_capture);
  537. return err;
  538. }
  539. int lx_pipe_sample_count(struct lx6464es *chip, u32 pipe, int is_capture,
  540. u64 *rsample_count)
  541. {
  542. int err;
  543. unsigned long flags;
  544. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  545. spin_lock_irqsave(&chip->msg_lock, flags);
  546. lx_message_init(&chip->rmh, CMD_0A_GET_PIPE_SPL_COUNT);
  547. chip->rmh.cmd[0] |= pipe_cmd;
  548. chip->rmh.stat_len = 2; /* need all words here! */
  549. err = lx_message_send_atomic(chip, &chip->rmh); /* don't sleep! */
  550. if (err != 0)
  551. snd_printk(KERN_ERR
  552. "lx6464es: could not query pipe's sample count\n");
  553. else {
  554. *rsample_count = ((u64)(chip->rmh.stat[0] & MASK_SPL_COUNT_HI)
  555. << 24) /* hi part */
  556. + chip->rmh.stat[1]; /* lo part */
  557. }
  558. spin_unlock_irqrestore(&chip->msg_lock, flags);
  559. return err;
  560. }
  561. int lx_pipe_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 *rstate)
  562. {
  563. int err;
  564. unsigned long flags;
  565. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  566. spin_lock_irqsave(&chip->msg_lock, flags);
  567. lx_message_init(&chip->rmh, CMD_0A_GET_PIPE_SPL_COUNT);
  568. chip->rmh.cmd[0] |= pipe_cmd;
  569. err = lx_message_send_atomic(chip, &chip->rmh);
  570. if (err != 0)
  571. snd_printk(KERN_ERR "lx6464es: could not query pipe's state\n");
  572. else
  573. *rstate = (chip->rmh.stat[0] >> PSTATE_OFFSET) & 0x0F;
  574. spin_unlock_irqrestore(&chip->msg_lock, flags);
  575. return err;
  576. }
  577. static int lx_pipe_wait_for_state(struct lx6464es *chip, u32 pipe,
  578. int is_capture, u16 state)
  579. {
  580. int i;
  581. /* max 2*PCMOnlyGranularity = 2*1024 at 44100 = < 50 ms:
  582. * timeout 50 ms */
  583. for (i = 0; i != 50; ++i) {
  584. u16 current_state;
  585. int err = lx_pipe_state(chip, pipe, is_capture, &current_state);
  586. if (err < 0)
  587. return err;
  588. if (current_state == state)
  589. return 0;
  590. mdelay(1);
  591. }
  592. return -ETIMEDOUT;
  593. }
  594. int lx_pipe_wait_for_start(struct lx6464es *chip, u32 pipe, int is_capture)
  595. {
  596. return lx_pipe_wait_for_state(chip, pipe, is_capture, PSTATE_RUN);
  597. }
  598. int lx_pipe_wait_for_idle(struct lx6464es *chip, u32 pipe, int is_capture)
  599. {
  600. return lx_pipe_wait_for_state(chip, pipe, is_capture, PSTATE_IDLE);
  601. }
  602. /* low-level stream handling */
  603. int lx_stream_set_state(struct lx6464es *chip, u32 pipe,
  604. int is_capture, enum stream_state_t state)
  605. {
  606. int err;
  607. unsigned long flags;
  608. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  609. spin_lock_irqsave(&chip->msg_lock, flags);
  610. lx_message_init(&chip->rmh, CMD_13_SET_STREAM_STATE);
  611. chip->rmh.cmd[0] |= pipe_cmd;
  612. chip->rmh.cmd[0] |= state;
  613. err = lx_message_send_atomic(chip, &chip->rmh);
  614. spin_unlock_irqrestore(&chip->msg_lock, flags);
  615. return err;
  616. }
  617. int lx_stream_set_format(struct lx6464es *chip, struct snd_pcm_runtime *runtime,
  618. u32 pipe, int is_capture)
  619. {
  620. int err;
  621. unsigned long flags;
  622. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  623. u32 channels = runtime->channels;
  624. if (runtime->channels != channels)
  625. snd_printk(KERN_ERR LXP "channel count mismatch: %d vs %d",
  626. runtime->channels, channels);
  627. spin_lock_irqsave(&chip->msg_lock, flags);
  628. lx_message_init(&chip->rmh, CMD_0C_DEF_STREAM);
  629. chip->rmh.cmd[0] |= pipe_cmd;
  630. if (runtime->sample_bits == 16)
  631. /* 16 bit format */
  632. chip->rmh.cmd[0] |= (STREAM_FMT_16b << STREAM_FMT_OFFSET);
  633. if (snd_pcm_format_little_endian(runtime->format))
  634. /* little endian/intel format */
  635. chip->rmh.cmd[0] |= (STREAM_FMT_intel << STREAM_FMT_OFFSET);
  636. chip->rmh.cmd[0] |= channels-1;
  637. err = lx_message_send_atomic(chip, &chip->rmh);
  638. spin_unlock_irqrestore(&chip->msg_lock, flags);
  639. return err;
  640. }
  641. int lx_stream_state(struct lx6464es *chip, u32 pipe, int is_capture,
  642. int *rstate)
  643. {
  644. int err;
  645. unsigned long flags;
  646. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  647. spin_lock_irqsave(&chip->msg_lock, flags);
  648. lx_message_init(&chip->rmh, CMD_0E_GET_STREAM_SPL_COUNT);
  649. chip->rmh.cmd[0] |= pipe_cmd;
  650. err = lx_message_send_atomic(chip, &chip->rmh);
  651. *rstate = (chip->rmh.stat[0] & SF_START) ? START_STATE : PAUSE_STATE;
  652. spin_unlock_irqrestore(&chip->msg_lock, flags);
  653. return err;
  654. }
  655. int lx_stream_sample_position(struct lx6464es *chip, u32 pipe, int is_capture,
  656. u64 *r_bytepos)
  657. {
  658. int err;
  659. unsigned long flags;
  660. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  661. spin_lock_irqsave(&chip->msg_lock, flags);
  662. lx_message_init(&chip->rmh, CMD_0E_GET_STREAM_SPL_COUNT);
  663. chip->rmh.cmd[0] |= pipe_cmd;
  664. err = lx_message_send_atomic(chip, &chip->rmh);
  665. *r_bytepos = ((u64) (chip->rmh.stat[0] & MASK_SPL_COUNT_HI)
  666. << 32) /* hi part */
  667. + chip->rmh.stat[1]; /* lo part */
  668. spin_unlock_irqrestore(&chip->msg_lock, flags);
  669. return err;
  670. }
  671. /* low-level buffer handling */
  672. int lx_buffer_give(struct lx6464es *chip, u32 pipe, int is_capture,
  673. u32 buffer_size, u32 buf_address_lo, u32 buf_address_hi,
  674. u32 *r_buffer_index)
  675. {
  676. int err;
  677. unsigned long flags;
  678. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  679. spin_lock_irqsave(&chip->msg_lock, flags);
  680. lx_message_init(&chip->rmh, CMD_0F_UPDATE_BUFFER);
  681. chip->rmh.cmd[0] |= pipe_cmd;
  682. chip->rmh.cmd[0] |= BF_NOTIFY_EOB; /* request interrupt notification */
  683. /* todo: pause request, circular buffer */
  684. chip->rmh.cmd[1] = buffer_size & MASK_DATA_SIZE;
  685. chip->rmh.cmd[2] = buf_address_lo;
  686. if (buf_address_hi) {
  687. chip->rmh.cmd_len = 4;
  688. chip->rmh.cmd[3] = buf_address_hi;
  689. chip->rmh.cmd[0] |= BF_64BITS_ADR;
  690. }
  691. err = lx_message_send_atomic(chip, &chip->rmh);
  692. if (err == 0) {
  693. *r_buffer_index = chip->rmh.stat[0];
  694. goto done;
  695. }
  696. if (err == EB_RBUFFERS_TABLE_OVERFLOW)
  697. snd_printk(LXP "lx_buffer_give EB_RBUFFERS_TABLE_OVERFLOW\n");
  698. if (err == EB_INVALID_STREAM)
  699. snd_printk(LXP "lx_buffer_give EB_INVALID_STREAM\n");
  700. if (err == EB_CMD_REFUSED)
  701. snd_printk(LXP "lx_buffer_give EB_CMD_REFUSED\n");
  702. done:
  703. spin_unlock_irqrestore(&chip->msg_lock, flags);
  704. return err;
  705. }
  706. int lx_buffer_free(struct lx6464es *chip, u32 pipe, int is_capture,
  707. u32 *r_buffer_size)
  708. {
  709. int err;
  710. unsigned long flags;
  711. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  712. spin_lock_irqsave(&chip->msg_lock, flags);
  713. lx_message_init(&chip->rmh, CMD_11_CANCEL_BUFFER);
  714. chip->rmh.cmd[0] |= pipe_cmd;
  715. chip->rmh.cmd[0] |= MASK_BUFFER_ID; /* ask for the current buffer: the
  716. * microblaze will seek for it */
  717. err = lx_message_send_atomic(chip, &chip->rmh);
  718. if (err == 0)
  719. *r_buffer_size = chip->rmh.stat[0] & MASK_DATA_SIZE;
  720. spin_unlock_irqrestore(&chip->msg_lock, flags);
  721. return err;
  722. }
  723. int lx_buffer_cancel(struct lx6464es *chip, u32 pipe, int is_capture,
  724. u32 buffer_index)
  725. {
  726. int err;
  727. unsigned long flags;
  728. u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe);
  729. spin_lock_irqsave(&chip->msg_lock, flags);
  730. lx_message_init(&chip->rmh, CMD_11_CANCEL_BUFFER);
  731. chip->rmh.cmd[0] |= pipe_cmd;
  732. chip->rmh.cmd[0] |= buffer_index;
  733. err = lx_message_send_atomic(chip, &chip->rmh);
  734. spin_unlock_irqrestore(&chip->msg_lock, flags);
  735. return err;
  736. }
  737. /* low-level gain/peak handling
  738. *
  739. * \todo: can we unmute capture/playback channels independently?
  740. *
  741. * */
  742. int lx_level_unmute(struct lx6464es *chip, int is_capture, int unmute)
  743. {
  744. int err;
  745. unsigned long flags;
  746. /* bit set to 1: channel muted */
  747. u64 mute_mask = unmute ? 0 : 0xFFFFFFFFFFFFFFFFLLU;
  748. spin_lock_irqsave(&chip->msg_lock, flags);
  749. lx_message_init(&chip->rmh, CMD_0D_SET_MUTE);
  750. chip->rmh.cmd[0] |= PIPE_INFO_TO_CMD(is_capture, 0);
  751. chip->rmh.cmd[1] = (u32)(mute_mask >> (u64)32); /* hi part */
  752. chip->rmh.cmd[2] = (u32)(mute_mask & (u64)0xFFFFFFFF); /* lo part */
  753. snd_printk("mute %x %x %x\n", chip->rmh.cmd[0], chip->rmh.cmd[1],
  754. chip->rmh.cmd[2]);
  755. err = lx_message_send_atomic(chip, &chip->rmh);
  756. spin_unlock_irqrestore(&chip->msg_lock, flags);
  757. return err;
  758. }
  759. static u32 peak_map[] = {
  760. 0x00000109, /* -90.308dB */
  761. 0x0000083B, /* -72.247dB */
  762. 0x000020C4, /* -60.205dB */
  763. 0x00008273, /* -48.030dB */
  764. 0x00020756, /* -36.005dB */
  765. 0x00040C37, /* -30.001dB */
  766. 0x00081385, /* -24.002dB */
  767. 0x00101D3F, /* -18.000dB */
  768. 0x0016C310, /* -15.000dB */
  769. 0x002026F2, /* -12.001dB */
  770. 0x002D6A86, /* -9.000dB */
  771. 0x004026E6, /* -6.004dB */
  772. 0x005A9DF6, /* -3.000dB */
  773. 0x0065AC8B, /* -2.000dB */
  774. 0x00721481, /* -1.000dB */
  775. 0x007FFFFF, /* FS */
  776. };
  777. int lx_level_peaks(struct lx6464es *chip, int is_capture, int channels,
  778. u32 *r_levels)
  779. {
  780. int err = 0;
  781. unsigned long flags;
  782. int i;
  783. spin_lock_irqsave(&chip->msg_lock, flags);
  784. for (i = 0; i < channels; i += 4) {
  785. u32 s0, s1, s2, s3;
  786. lx_message_init(&chip->rmh, CMD_12_GET_PEAK);
  787. chip->rmh.cmd[0] |= PIPE_INFO_TO_CMD(is_capture, i);
  788. err = lx_message_send_atomic(chip, &chip->rmh);
  789. if (err == 0) {
  790. s0 = peak_map[chip->rmh.stat[0] & 0x0F];
  791. s1 = peak_map[(chip->rmh.stat[0] >> 4) & 0xf];
  792. s2 = peak_map[(chip->rmh.stat[0] >> 8) & 0xf];
  793. s3 = peak_map[(chip->rmh.stat[0] >> 12) & 0xf];
  794. } else
  795. s0 = s1 = s2 = s3 = 0;
  796. r_levels[0] = s0;
  797. r_levels[1] = s1;
  798. r_levels[2] = s2;
  799. r_levels[3] = s3;
  800. r_levels += 4;
  801. }
  802. spin_unlock_irqrestore(&chip->msg_lock, flags);
  803. return err;
  804. }
  805. /* interrupt handling */
  806. #define PCX_IRQ_NONE 0
  807. #define IRQCS_ACTIVE_PCIDB 0x00002000L /* Bit nø 13 */
  808. #define IRQCS_ENABLE_PCIIRQ 0x00000100L /* Bit nø 08 */
  809. #define IRQCS_ENABLE_PCIDB 0x00000200L /* Bit nø 09 */
  810. static u32 lx_interrupt_test_ack(struct lx6464es *chip)
  811. {
  812. u32 irqcs = lx_plx_reg_read(chip, ePLX_IRQCS);
  813. /* Test if PCI Doorbell interrupt is active */
  814. if (irqcs & IRQCS_ACTIVE_PCIDB) {
  815. u32 temp;
  816. irqcs = PCX_IRQ_NONE;
  817. while ((temp = lx_plx_reg_read(chip, ePLX_L2PCIDB))) {
  818. /* RAZ interrupt */
  819. irqcs |= temp;
  820. lx_plx_reg_write(chip, ePLX_L2PCIDB, temp);
  821. }
  822. return irqcs;
  823. }
  824. return PCX_IRQ_NONE;
  825. }
  826. static int lx_interrupt_ack(struct lx6464es *chip, u32 *r_irqsrc,
  827. int *r_async_pending, int *r_async_escmd)
  828. {
  829. u32 irq_async;
  830. u32 irqsrc = lx_interrupt_test_ack(chip);
  831. if (irqsrc == PCX_IRQ_NONE)
  832. return 0;
  833. *r_irqsrc = irqsrc;
  834. irq_async = irqsrc & MASK_SYS_ASYNC_EVENTS; /* + EtherSound response
  835. * (set by xilinx) + EOB */
  836. if (irq_async & MASK_SYS_STATUS_ESA) {
  837. irq_async &= ~MASK_SYS_STATUS_ESA;
  838. *r_async_escmd = 1;
  839. }
  840. if (irq_async) {
  841. /* snd_printd("interrupt: async event pending\n"); */
  842. *r_async_pending = 1;
  843. }
  844. return 1;
  845. }
  846. static int lx_interrupt_handle_async_events(struct lx6464es *chip, u32 irqsrc,
  847. int *r_freq_changed,
  848. u64 *r_notified_in_pipe_mask,
  849. u64 *r_notified_out_pipe_mask)
  850. {
  851. int err;
  852. u32 stat[9]; /* answer from CMD_04_GET_EVENT */
  853. /* On peut optimiser pour ne pas lire les evenements vides
  854. * les mots de réponse sont dans l'ordre suivant :
  855. * Stat[0] mot de status général
  856. * Stat[1] fin de buffer OUT pF
  857. * Stat[2] fin de buffer OUT pf
  858. * Stat[3] fin de buffer IN pF
  859. * Stat[4] fin de buffer IN pf
  860. * Stat[5] underrun poid fort
  861. * Stat[6] underrun poid faible
  862. * Stat[7] overrun poid fort
  863. * Stat[8] overrun poid faible
  864. * */
  865. u64 orun_mask;
  866. u64 urun_mask;
  867. #if 0
  868. int has_underrun = (irqsrc & MASK_SYS_STATUS_URUN) ? 1 : 0;
  869. int has_overrun = (irqsrc & MASK_SYS_STATUS_ORUN) ? 1 : 0;
  870. #endif
  871. int eb_pending_out = (irqsrc & MASK_SYS_STATUS_EOBO) ? 1 : 0;
  872. int eb_pending_in = (irqsrc & MASK_SYS_STATUS_EOBI) ? 1 : 0;
  873. *r_freq_changed = (irqsrc & MASK_SYS_STATUS_FREQ) ? 1 : 0;
  874. err = lx_dsp_read_async_events(chip, stat);
  875. if (err < 0)
  876. return err;
  877. if (eb_pending_in) {
  878. *r_notified_in_pipe_mask = ((u64)stat[3] << 32)
  879. + stat[4];
  880. snd_printdd(LXP "interrupt: EOBI pending %llx\n",
  881. *r_notified_in_pipe_mask);
  882. }
  883. if (eb_pending_out) {
  884. *r_notified_out_pipe_mask = ((u64)stat[1] << 32)
  885. + stat[2];
  886. snd_printdd(LXP "interrupt: EOBO pending %llx\n",
  887. *r_notified_out_pipe_mask);
  888. }
  889. orun_mask = ((u64)stat[7] << 32) + stat[8];
  890. urun_mask = ((u64)stat[5] << 32) + stat[6];
  891. /* todo: handle xrun notification */
  892. return err;
  893. }
  894. static int lx_interrupt_request_new_buffer(struct lx6464es *chip,
  895. struct lx_stream *lx_stream)
  896. {
  897. struct snd_pcm_substream *substream = lx_stream->stream;
  898. int is_capture = lx_stream->is_capture;
  899. int err;
  900. unsigned long flags;
  901. const u32 channels = substream->runtime->channels;
  902. const u32 bytes_per_frame = channels * 3;
  903. const u32 period_size = substream->runtime->period_size;
  904. const u32 period_bytes = period_size * bytes_per_frame;
  905. const u32 pos = lx_stream->frame_pos;
  906. const u32 next_pos = ((pos+1) == substream->runtime->periods) ?
  907. 0 : pos + 1;
  908. dma_addr_t buf = substream->dma_buffer.addr + pos * period_bytes;
  909. u32 buf_hi = 0;
  910. u32 buf_lo = 0;
  911. u32 buffer_index = 0;
  912. u32 needed, freed;
  913. u32 size_array[MAX_STREAM_BUFFER];
  914. snd_printdd("->lx_interrupt_request_new_buffer\n");
  915. spin_lock_irqsave(&chip->lock, flags);
  916. err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
  917. snd_printdd(LXP "interrupt: needed %d, freed %d\n", needed, freed);
  918. unpack_pointer(buf, &buf_lo, &buf_hi);
  919. err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi,
  920. &buffer_index);
  921. snd_printdd(LXP "interrupt: gave buffer index %x on %p (%d bytes)\n",
  922. buffer_index, (void *)buf, period_bytes);
  923. lx_stream->frame_pos = next_pos;
  924. spin_unlock_irqrestore(&chip->lock, flags);
  925. return err;
  926. }
  927. void lx_tasklet_playback(unsigned long data)
  928. {
  929. struct lx6464es *chip = (struct lx6464es *)data;
  930. struct lx_stream *lx_stream = &chip->playback_stream;
  931. int err;
  932. snd_printdd("->lx_tasklet_playback\n");
  933. err = lx_interrupt_request_new_buffer(chip, lx_stream);
  934. if (err < 0)
  935. snd_printk(KERN_ERR LXP
  936. "cannot request new buffer for playback\n");
  937. snd_pcm_period_elapsed(lx_stream->stream);
  938. }
  939. void lx_tasklet_capture(unsigned long data)
  940. {
  941. struct lx6464es *chip = (struct lx6464es *)data;
  942. struct lx_stream *lx_stream = &chip->capture_stream;
  943. int err;
  944. snd_printdd("->lx_tasklet_capture\n");
  945. err = lx_interrupt_request_new_buffer(chip, lx_stream);
  946. if (err < 0)
  947. snd_printk(KERN_ERR LXP
  948. "cannot request new buffer for capture\n");
  949. snd_pcm_period_elapsed(lx_stream->stream);
  950. }
  951. static int lx_interrupt_handle_audio_transfer(struct lx6464es *chip,
  952. u64 notified_in_pipe_mask,
  953. u64 notified_out_pipe_mask)
  954. {
  955. int err = 0;
  956. if (notified_in_pipe_mask) {
  957. snd_printdd(LXP "requesting audio transfer for capture\n");
  958. tasklet_hi_schedule(&chip->tasklet_capture);
  959. }
  960. if (notified_out_pipe_mask) {
  961. snd_printdd(LXP "requesting audio transfer for playback\n");
  962. tasklet_hi_schedule(&chip->tasklet_playback);
  963. }
  964. return err;
  965. }
  966. irqreturn_t lx_interrupt(int irq, void *dev_id)
  967. {
  968. struct lx6464es *chip = dev_id;
  969. int async_pending, async_escmd;
  970. u32 irqsrc;
  971. spin_lock(&chip->lock);
  972. snd_printdd("**************************************************\n");
  973. if (!lx_interrupt_ack(chip, &irqsrc, &async_pending, &async_escmd)) {
  974. spin_unlock(&chip->lock);
  975. snd_printdd("IRQ_NONE\n");
  976. return IRQ_NONE; /* this device did not cause the interrupt */
  977. }
  978. if (irqsrc & MASK_SYS_STATUS_CMD_DONE)
  979. goto exit;
  980. #if 0
  981. if (irqsrc & MASK_SYS_STATUS_EOBI)
  982. snd_printdd(LXP "interrupt: EOBI\n");
  983. if (irqsrc & MASK_SYS_STATUS_EOBO)
  984. snd_printdd(LXP "interrupt: EOBO\n");
  985. if (irqsrc & MASK_SYS_STATUS_URUN)
  986. snd_printdd(LXP "interrupt: URUN\n");
  987. if (irqsrc & MASK_SYS_STATUS_ORUN)
  988. snd_printdd(LXP "interrupt: ORUN\n");
  989. #endif
  990. if (async_pending) {
  991. u64 notified_in_pipe_mask = 0;
  992. u64 notified_out_pipe_mask = 0;
  993. int freq_changed;
  994. int err;
  995. /* handle async events */
  996. err = lx_interrupt_handle_async_events(chip, irqsrc,
  997. &freq_changed,
  998. &notified_in_pipe_mask,
  999. &notified_out_pipe_mask);
  1000. if (err)
  1001. snd_printk(KERN_ERR LXP
  1002. "error handling async events\n");
  1003. err = lx_interrupt_handle_audio_transfer(chip,
  1004. notified_in_pipe_mask,
  1005. notified_out_pipe_mask
  1006. );
  1007. if (err)
  1008. snd_printk(KERN_ERR LXP
  1009. "error during audio transfer\n");
  1010. }
  1011. if (async_escmd) {
  1012. #if 0
  1013. /* backdoor for ethersound commands
  1014. *
  1015. * for now, we do not need this
  1016. *
  1017. * */
  1018. snd_printdd("lx6464es: interrupt requests escmd handling\n");
  1019. #endif
  1020. }
  1021. exit:
  1022. spin_unlock(&chip->lock);
  1023. return IRQ_HANDLED; /* this device caused the interrupt */
  1024. }
  1025. static void lx_irq_set(struct lx6464es *chip, int enable)
  1026. {
  1027. u32 reg = lx_plx_reg_read(chip, ePLX_IRQCS);
  1028. /* enable/disable interrupts
  1029. *
  1030. * Set the Doorbell and PCI interrupt enable bits
  1031. *
  1032. * */
  1033. if (enable)
  1034. reg |= (IRQCS_ENABLE_PCIIRQ | IRQCS_ENABLE_PCIDB);
  1035. else
  1036. reg &= ~(IRQCS_ENABLE_PCIIRQ | IRQCS_ENABLE_PCIDB);
  1037. lx_plx_reg_write(chip, ePLX_IRQCS, reg);
  1038. }
  1039. void lx_irq_enable(struct lx6464es *chip)
  1040. {
  1041. snd_printdd("->lx_irq_enable\n");
  1042. lx_irq_set(chip, 1);
  1043. }
  1044. void lx_irq_disable(struct lx6464es *chip)
  1045. {
  1046. snd_printdd("->lx_irq_disable\n");
  1047. lx_irq_set(chip, 0);
  1048. }