pdaudiocf_irq.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * Driver for Sound Core PDAudioCF soundcard
  3. *
  4. * Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
  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. #include <sound/core.h>
  21. #include "pdaudiocf.h"
  22. #include <sound/initval.h>
  23. #include <asm/irq_regs.h>
  24. /*
  25. *
  26. */
  27. irqreturn_t pdacf_interrupt(int irq, void *dev)
  28. {
  29. struct snd_pdacf *chip = dev;
  30. unsigned short stat;
  31. if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE|
  32. PDAUDIOCF_STAT_IS_CONFIGURED|
  33. PDAUDIOCF_STAT_IS_SUSPENDED)) != PDAUDIOCF_STAT_IS_CONFIGURED)
  34. return IRQ_HANDLED; /* IRQ_NONE here? */
  35. stat = inw(chip->port + PDAUDIOCF_REG_ISR);
  36. if (stat & (PDAUDIOCF_IRQLVL|PDAUDIOCF_IRQOVR)) {
  37. if (stat & PDAUDIOCF_IRQOVR) /* should never happen */
  38. snd_printk(KERN_ERR "PDAUDIOCF SRAM buffer overrun detected!\n");
  39. if (chip->pcm_substream)
  40. tasklet_schedule(&chip->tq);
  41. if (!(stat & PDAUDIOCF_IRQAKM))
  42. stat |= PDAUDIOCF_IRQAKM; /* check rate */
  43. }
  44. if (get_irq_regs() != NULL)
  45. snd_ak4117_check_rate_and_errors(chip->ak4117, 0);
  46. return IRQ_HANDLED;
  47. }
  48. static inline void pdacf_transfer_mono16(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  49. {
  50. while (size-- > 0) {
  51. *dst++ = inw(rdp_port) ^ xor;
  52. inw(rdp_port);
  53. }
  54. }
  55. static inline void pdacf_transfer_mono32(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  56. {
  57. register u16 val1, val2;
  58. while (size-- > 0) {
  59. val1 = inw(rdp_port);
  60. val2 = inw(rdp_port);
  61. inw(rdp_port);
  62. *dst++ = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor;
  63. }
  64. }
  65. static inline void pdacf_transfer_stereo16(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  66. {
  67. while (size-- > 0) {
  68. *dst++ = inw(rdp_port) ^ xor;
  69. *dst++ = inw(rdp_port) ^ xor;
  70. }
  71. }
  72. static inline void pdacf_transfer_stereo32(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  73. {
  74. register u16 val1, val2, val3;
  75. while (size-- > 0) {
  76. val1 = inw(rdp_port);
  77. val2 = inw(rdp_port);
  78. val3 = inw(rdp_port);
  79. *dst++ = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor;
  80. *dst++ = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor;
  81. }
  82. }
  83. static inline void pdacf_transfer_mono16sw(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  84. {
  85. while (size-- > 0) {
  86. *dst++ = swab16(inw(rdp_port) ^ xor);
  87. inw(rdp_port);
  88. }
  89. }
  90. static inline void pdacf_transfer_mono32sw(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  91. {
  92. register u16 val1, val2;
  93. while (size-- > 0) {
  94. val1 = inw(rdp_port);
  95. val2 = inw(rdp_port);
  96. inw(rdp_port);
  97. *dst++ = swab32((((val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor);
  98. }
  99. }
  100. static inline void pdacf_transfer_stereo16sw(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  101. {
  102. while (size-- > 0) {
  103. *dst++ = swab16(inw(rdp_port) ^ xor);
  104. *dst++ = swab16(inw(rdp_port) ^ xor);
  105. }
  106. }
  107. static inline void pdacf_transfer_stereo32sw(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  108. {
  109. register u16 val1, val2, val3;
  110. while (size-- > 0) {
  111. val1 = inw(rdp_port);
  112. val2 = inw(rdp_port);
  113. val3 = inw(rdp_port);
  114. *dst++ = swab32((((val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor);
  115. *dst++ = swab32((((u32)val3 << 16) | (val2 & 0xff00)) ^ xor);
  116. }
  117. }
  118. static inline void pdacf_transfer_mono24le(u8 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  119. {
  120. register u16 val1, val2;
  121. register u32 xval1;
  122. while (size-- > 0) {
  123. val1 = inw(rdp_port);
  124. val2 = inw(rdp_port);
  125. inw(rdp_port);
  126. xval1 = (((val2 & 0xff) << 8) | (val1 << 16)) ^ xor;
  127. *dst++ = (u8)(xval1 >> 8);
  128. *dst++ = (u8)(xval1 >> 16);
  129. *dst++ = (u8)(xval1 >> 24);
  130. }
  131. }
  132. static inline void pdacf_transfer_mono24be(u8 *dst, u16 xor, unsigned int size, unsigned long rdp_port)
  133. {
  134. register u16 val1, val2;
  135. register u32 xval1;
  136. while (size-- > 0) {
  137. val1 = inw(rdp_port);
  138. val2 = inw(rdp_port);
  139. inw(rdp_port);
  140. xval1 = (((val2 & 0xff) << 8) | (val1 << 16)) ^ xor;
  141. *dst++ = (u8)(xval1 >> 24);
  142. *dst++ = (u8)(xval1 >> 16);
  143. *dst++ = (u8)(xval1 >> 8);
  144. }
  145. }
  146. static inline void pdacf_transfer_stereo24le(u8 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  147. {
  148. register u16 val1, val2, val3;
  149. register u32 xval1, xval2;
  150. while (size-- > 0) {
  151. val1 = inw(rdp_port);
  152. val2 = inw(rdp_port);
  153. val3 = inw(rdp_port);
  154. xval1 = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor;
  155. xval2 = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor;
  156. *dst++ = (u8)(xval1 >> 8);
  157. *dst++ = (u8)(xval1 >> 16);
  158. *dst++ = (u8)(xval1 >> 24);
  159. *dst++ = (u8)(xval2 >> 8);
  160. *dst++ = (u8)(xval2 >> 16);
  161. *dst++ = (u8)(xval2 >> 24);
  162. }
  163. }
  164. static inline void pdacf_transfer_stereo24be(u8 *dst, u32 xor, unsigned int size, unsigned long rdp_port)
  165. {
  166. register u16 val1, val2, val3;
  167. register u32 xval1, xval2;
  168. while (size-- > 0) {
  169. val1 = inw(rdp_port);
  170. val2 = inw(rdp_port);
  171. val3 = inw(rdp_port);
  172. xval1 = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor;
  173. xval2 = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor;
  174. *dst++ = (u8)(xval1 >> 24);
  175. *dst++ = (u8)(xval1 >> 16);
  176. *dst++ = (u8)(xval1 >> 8);
  177. *dst++ = (u8)(xval2 >> 24);
  178. *dst++ = (u8)(xval2 >> 16);
  179. *dst++ = (u8)(xval2 >> 8);
  180. }
  181. }
  182. static void pdacf_transfer(struct snd_pdacf *chip, unsigned int size, unsigned int off)
  183. {
  184. unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD;
  185. unsigned int xor = chip->pcm_xor;
  186. if (chip->pcm_sample == 3) {
  187. if (chip->pcm_little) {
  188. if (chip->pcm_channels == 1) {
  189. pdacf_transfer_mono24le((char *)chip->pcm_area + (off * 3), xor, size, rdp_port);
  190. } else {
  191. pdacf_transfer_stereo24le((char *)chip->pcm_area + (off * 6), xor, size, rdp_port);
  192. }
  193. } else {
  194. if (chip->pcm_channels == 1) {
  195. pdacf_transfer_mono24be((char *)chip->pcm_area + (off * 3), xor, size, rdp_port);
  196. } else {
  197. pdacf_transfer_stereo24be((char *)chip->pcm_area + (off * 6), xor, size, rdp_port);
  198. }
  199. }
  200. return;
  201. }
  202. if (chip->pcm_swab == 0) {
  203. if (chip->pcm_channels == 1) {
  204. if (chip->pcm_frame == 2) {
  205. pdacf_transfer_mono16((u16 *)chip->pcm_area + off, xor, size, rdp_port);
  206. } else {
  207. pdacf_transfer_mono32((u32 *)chip->pcm_area + off, xor, size, rdp_port);
  208. }
  209. } else {
  210. if (chip->pcm_frame == 2) {
  211. pdacf_transfer_stereo16((u16 *)chip->pcm_area + (off * 2), xor, size, rdp_port);
  212. } else {
  213. pdacf_transfer_stereo32((u32 *)chip->pcm_area + (off * 2), xor, size, rdp_port);
  214. }
  215. }
  216. } else {
  217. if (chip->pcm_channels == 1) {
  218. if (chip->pcm_frame == 2) {
  219. pdacf_transfer_mono16sw((u16 *)chip->pcm_area + off, xor, size, rdp_port);
  220. } else {
  221. pdacf_transfer_mono32sw((u32 *)chip->pcm_area + off, xor, size, rdp_port);
  222. }
  223. } else {
  224. if (chip->pcm_frame == 2) {
  225. pdacf_transfer_stereo16sw((u16 *)chip->pcm_area + (off * 2), xor, size, rdp_port);
  226. } else {
  227. pdacf_transfer_stereo32sw((u32 *)chip->pcm_area + (off * 2), xor, size, rdp_port);
  228. }
  229. }
  230. }
  231. }
  232. void pdacf_tasklet(unsigned long private_data)
  233. {
  234. struct snd_pdacf *chip = (struct snd_pdacf *) private_data;
  235. int size, off, cont, rdp, wdp;
  236. if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE|PDAUDIOCF_STAT_IS_CONFIGURED)) != PDAUDIOCF_STAT_IS_CONFIGURED)
  237. return;
  238. if (chip->pcm_substream == NULL || chip->pcm_substream->runtime == NULL || !snd_pcm_running(chip->pcm_substream))
  239. return;
  240. rdp = inw(chip->port + PDAUDIOCF_REG_RDP);
  241. wdp = inw(chip->port + PDAUDIOCF_REG_WDP);
  242. /* printk(KERN_DEBUG "TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); */
  243. size = wdp - rdp;
  244. if (size < 0)
  245. size += 0x10000;
  246. if (size == 0)
  247. size = 0x10000;
  248. size /= chip->pcm_frame;
  249. if (size > 64)
  250. size -= 32;
  251. #if 0
  252. chip->pcm_hwptr += size;
  253. chip->pcm_hwptr %= chip->pcm_size;
  254. chip->pcm_tdone += size;
  255. if (chip->pcm_frame == 2) {
  256. unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD;
  257. while (size-- > 0) {
  258. inw(rdp_port);
  259. inw(rdp_port);
  260. }
  261. } else {
  262. unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD;
  263. while (size-- > 0) {
  264. inw(rdp_port);
  265. inw(rdp_port);
  266. inw(rdp_port);
  267. }
  268. }
  269. #else
  270. off = chip->pcm_hwptr + chip->pcm_tdone;
  271. off %= chip->pcm_size;
  272. chip->pcm_tdone += size;
  273. while (size > 0) {
  274. cont = chip->pcm_size - off;
  275. if (cont > size)
  276. cont = size;
  277. pdacf_transfer(chip, cont, off);
  278. off += cont;
  279. off %= chip->pcm_size;
  280. size -= cont;
  281. }
  282. #endif
  283. spin_lock(&chip->reg_lock);
  284. while (chip->pcm_tdone >= chip->pcm_period) {
  285. chip->pcm_hwptr += chip->pcm_period;
  286. chip->pcm_hwptr %= chip->pcm_size;
  287. chip->pcm_tdone -= chip->pcm_period;
  288. spin_unlock(&chip->reg_lock);
  289. snd_pcm_period_elapsed(chip->pcm_substream);
  290. spin_lock(&chip->reg_lock);
  291. }
  292. spin_unlock(&chip->reg_lock);
  293. /* printk(KERN_DEBUG "TASKLET: end\n"); */
  294. }