dmasound_paula.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * linux/sound/oss/dmasound/dmasound_paula.c
  3. *
  4. * Amiga `Paula' DMA Sound Driver
  5. *
  6. * See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
  7. * prior to 28/01/2001
  8. *
  9. * 28/01/2001 [0.1] Iain Sandoe
  10. * - added versioning
  11. * - put in and populated the hardware_afmts field.
  12. * [0.2] - put in SNDCTL_DSP_GETCAPS value.
  13. * [0.3] - put in constraint on state buffer usage.
  14. * [0.4] - put in default hard/soft settings
  15. */
  16. #include <linux/module.h>
  17. #include <linux/mm.h>
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <linux/soundcard.h>
  21. #include <linux/interrupt.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/setup.h>
  24. #include <asm/amigahw.h>
  25. #include <asm/amigaints.h>
  26. #include <asm/machdep.h>
  27. #include "dmasound.h"
  28. #define DMASOUND_PAULA_REVISION 0
  29. #define DMASOUND_PAULA_EDITION 4
  30. #define custom amiga_custom
  31. /*
  32. * The minimum period for audio depends on htotal (for OCS/ECS/AGA)
  33. * (Imported from arch/m68k/amiga/amisound.c)
  34. */
  35. extern volatile u_short amiga_audio_min_period;
  36. /*
  37. * amiga_mksound() should be able to restore the period after beeping
  38. * (Imported from arch/m68k/amiga/amisound.c)
  39. */
  40. extern u_short amiga_audio_period;
  41. /*
  42. * Audio DMA masks
  43. */
  44. #define AMI_AUDIO_OFF (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
  45. #define AMI_AUDIO_8 (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
  46. #define AMI_AUDIO_14 (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
  47. /*
  48. * Helper pointers for 16(14)-bit sound
  49. */
  50. static int write_sq_block_size_half, write_sq_block_size_quarter;
  51. /*** Low level stuff *********************************************************/
  52. static void *AmiAlloc(unsigned int size, gfp_t flags);
  53. static void AmiFree(void *obj, unsigned int size);
  54. static int AmiIrqInit(void);
  55. #ifdef MODULE
  56. static void AmiIrqCleanUp(void);
  57. #endif
  58. static void AmiSilence(void);
  59. static void AmiInit(void);
  60. static int AmiSetFormat(int format);
  61. static int AmiSetVolume(int volume);
  62. static int AmiSetTreble(int treble);
  63. static void AmiPlayNextFrame(int index);
  64. static void AmiPlay(void);
  65. static irqreturn_t AmiInterrupt(int irq, void *dummy);
  66. #ifdef CONFIG_HEARTBEAT
  67. /*
  68. * Heartbeat interferes with sound since the 7 kHz low-pass filter and the
  69. * power LED are controlled by the same line.
  70. */
  71. #ifdef CONFIG_APUS
  72. #define mach_heartbeat ppc_md.heartbeat
  73. #endif
  74. static void (*saved_heartbeat)(int) = NULL;
  75. static inline void disable_heartbeat(void)
  76. {
  77. if (mach_heartbeat) {
  78. saved_heartbeat = mach_heartbeat;
  79. mach_heartbeat = NULL;
  80. }
  81. AmiSetTreble(dmasound.treble);
  82. }
  83. static inline void enable_heartbeat(void)
  84. {
  85. if (saved_heartbeat)
  86. mach_heartbeat = saved_heartbeat;
  87. }
  88. #else /* !CONFIG_HEARTBEAT */
  89. #define disable_heartbeat() do { } while (0)
  90. #define enable_heartbeat() do { } while (0)
  91. #endif /* !CONFIG_HEARTBEAT */
  92. /*** Mid level stuff *********************************************************/
  93. static void AmiMixerInit(void);
  94. static int AmiMixerIoctl(u_int cmd, u_long arg);
  95. static int AmiWriteSqSetup(void);
  96. static int AmiStateInfo(char *buffer, size_t space);
  97. /*** Translations ************************************************************/
  98. /* ++TeSche: radically changed for new expanding purposes...
  99. *
  100. * These two routines now deal with copying/expanding/translating the samples
  101. * from user space into our buffer at the right frequency. They take care about
  102. * how much data there's actually to read, how much buffer space there is and
  103. * to convert samples into the right frequency/encoding. They will only work on
  104. * complete samples so it may happen they leave some bytes in the input stream
  105. * if the user didn't write a multiple of the current sample size. They both
  106. * return the number of bytes they've used from both streams so you may detect
  107. * such a situation. Luckily all programs should be able to cope with that.
  108. *
  109. * I think I've optimized anything as far as one can do in plain C, all
  110. * variables should fit in registers and the loops are really short. There's
  111. * one loop for every possible situation. Writing a more generalized and thus
  112. * parameterized loop would only produce slower code. Feel free to optimize
  113. * this in assembler if you like. :)
  114. *
  115. * I think these routines belong here because they're not yet really hardware
  116. * independent, especially the fact that the Falcon can play 16bit samples
  117. * only in stereo is hardcoded in both of them!
  118. *
  119. * ++geert: split in even more functions (one per format)
  120. */
  121. /*
  122. * Native format
  123. */
  124. static ssize_t ami_ct_s8(const u_char __user *userPtr, size_t userCount,
  125. u_char frame[], ssize_t *frameUsed, ssize_t frameLeft)
  126. {
  127. ssize_t count, used;
  128. if (!dmasound.soft.stereo) {
  129. void *p = &frame[*frameUsed];
  130. count = min_t(unsigned long, userCount, frameLeft) & ~1;
  131. used = count;
  132. if (copy_from_user(p, userPtr, count))
  133. return -EFAULT;
  134. } else {
  135. u_char *left = &frame[*frameUsed>>1];
  136. u_char *right = left+write_sq_block_size_half;
  137. count = min_t(unsigned long, userCount, frameLeft)>>1 & ~1;
  138. used = count*2;
  139. while (count > 0) {
  140. if (get_user(*left++, userPtr++)
  141. || get_user(*right++, userPtr++))
  142. return -EFAULT;
  143. count--;
  144. }
  145. }
  146. *frameUsed += used;
  147. return used;
  148. }
  149. /*
  150. * Copy and convert 8 bit data
  151. */
  152. #define GENERATE_AMI_CT8(funcname, convsample) \
  153. static ssize_t funcname(const u_char __user *userPtr, size_t userCount, \
  154. u_char frame[], ssize_t *frameUsed, \
  155. ssize_t frameLeft) \
  156. { \
  157. ssize_t count, used; \
  158. \
  159. if (!dmasound.soft.stereo) { \
  160. u_char *p = &frame[*frameUsed]; \
  161. count = min_t(size_t, userCount, frameLeft) & ~1; \
  162. used = count; \
  163. while (count > 0) { \
  164. u_char data; \
  165. if (get_user(data, userPtr++)) \
  166. return -EFAULT; \
  167. *p++ = convsample(data); \
  168. count--; \
  169. } \
  170. } else { \
  171. u_char *left = &frame[*frameUsed>>1]; \
  172. u_char *right = left+write_sq_block_size_half; \
  173. count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
  174. used = count*2; \
  175. while (count > 0) { \
  176. u_char data; \
  177. if (get_user(data, userPtr++)) \
  178. return -EFAULT; \
  179. *left++ = convsample(data); \
  180. if (get_user(data, userPtr++)) \
  181. return -EFAULT; \
  182. *right++ = convsample(data); \
  183. count--; \
  184. } \
  185. } \
  186. *frameUsed += used; \
  187. return used; \
  188. }
  189. #define AMI_CT_ULAW(x) (dmasound_ulaw2dma8[(x)])
  190. #define AMI_CT_ALAW(x) (dmasound_alaw2dma8[(x)])
  191. #define AMI_CT_U8(x) ((x) ^ 0x80)
  192. GENERATE_AMI_CT8(ami_ct_ulaw, AMI_CT_ULAW)
  193. GENERATE_AMI_CT8(ami_ct_alaw, AMI_CT_ALAW)
  194. GENERATE_AMI_CT8(ami_ct_u8, AMI_CT_U8)
  195. /*
  196. * Copy and convert 16 bit data
  197. */
  198. #define GENERATE_AMI_CT_16(funcname, convsample) \
  199. static ssize_t funcname(const u_char __user *userPtr, size_t userCount, \
  200. u_char frame[], ssize_t *frameUsed, \
  201. ssize_t frameLeft) \
  202. { \
  203. const u_short __user *ptr = (const u_short __user *)userPtr; \
  204. ssize_t count, used; \
  205. u_short data; \
  206. \
  207. if (!dmasound.soft.stereo) { \
  208. u_char *high = &frame[*frameUsed>>1]; \
  209. u_char *low = high+write_sq_block_size_half; \
  210. count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
  211. used = count*2; \
  212. while (count > 0) { \
  213. if (get_user(data, ptr++)) \
  214. return -EFAULT; \
  215. data = convsample(data); \
  216. *high++ = data>>8; \
  217. *low++ = (data>>2) & 0x3f; \
  218. count--; \
  219. } \
  220. } else { \
  221. u_char *lefth = &frame[*frameUsed>>2]; \
  222. u_char *leftl = lefth+write_sq_block_size_quarter; \
  223. u_char *righth = lefth+write_sq_block_size_half; \
  224. u_char *rightl = righth+write_sq_block_size_quarter; \
  225. count = min_t(size_t, userCount, frameLeft)>>2 & ~1; \
  226. used = count*4; \
  227. while (count > 0) { \
  228. if (get_user(data, ptr++)) \
  229. return -EFAULT; \
  230. data = convsample(data); \
  231. *lefth++ = data>>8; \
  232. *leftl++ = (data>>2) & 0x3f; \
  233. if (get_user(data, ptr++)) \
  234. return -EFAULT; \
  235. data = convsample(data); \
  236. *righth++ = data>>8; \
  237. *rightl++ = (data>>2) & 0x3f; \
  238. count--; \
  239. } \
  240. } \
  241. *frameUsed += used; \
  242. return used; \
  243. }
  244. #define AMI_CT_S16BE(x) (x)
  245. #define AMI_CT_U16BE(x) ((x) ^ 0x8000)
  246. #define AMI_CT_S16LE(x) (le2be16((x)))
  247. #define AMI_CT_U16LE(x) (le2be16((x)) ^ 0x8000)
  248. GENERATE_AMI_CT_16(ami_ct_s16be, AMI_CT_S16BE)
  249. GENERATE_AMI_CT_16(ami_ct_u16be, AMI_CT_U16BE)
  250. GENERATE_AMI_CT_16(ami_ct_s16le, AMI_CT_S16LE)
  251. GENERATE_AMI_CT_16(ami_ct_u16le, AMI_CT_U16LE)
  252. static TRANS transAmiga = {
  253. .ct_ulaw = ami_ct_ulaw,
  254. .ct_alaw = ami_ct_alaw,
  255. .ct_s8 = ami_ct_s8,
  256. .ct_u8 = ami_ct_u8,
  257. .ct_s16be = ami_ct_s16be,
  258. .ct_u16be = ami_ct_u16be,
  259. .ct_s16le = ami_ct_s16le,
  260. .ct_u16le = ami_ct_u16le,
  261. };
  262. /*** Low level stuff *********************************************************/
  263. static inline void StopDMA(void)
  264. {
  265. custom.aud[0].audvol = custom.aud[1].audvol = 0;
  266. custom.aud[2].audvol = custom.aud[3].audvol = 0;
  267. custom.dmacon = AMI_AUDIO_OFF;
  268. enable_heartbeat();
  269. }
  270. static void *AmiAlloc(unsigned int size, gfp_t flags)
  271. {
  272. return amiga_chip_alloc((long)size, "dmasound [Paula]");
  273. }
  274. static void AmiFree(void *obj, unsigned int size)
  275. {
  276. amiga_chip_free (obj);
  277. }
  278. static int __init AmiIrqInit(void)
  279. {
  280. /* turn off DMA for audio channels */
  281. StopDMA();
  282. /* Register interrupt handler. */
  283. if (request_irq(IRQ_AMIGA_AUD0, AmiInterrupt, 0, "DMA sound",
  284. AmiInterrupt))
  285. return 0;
  286. return 1;
  287. }
  288. #ifdef MODULE
  289. static void AmiIrqCleanUp(void)
  290. {
  291. /* turn off DMA for audio channels */
  292. StopDMA();
  293. /* release the interrupt */
  294. free_irq(IRQ_AMIGA_AUD0, AmiInterrupt);
  295. }
  296. #endif /* MODULE */
  297. static void AmiSilence(void)
  298. {
  299. /* turn off DMA for audio channels */
  300. StopDMA();
  301. }
  302. static void AmiInit(void)
  303. {
  304. int period, i;
  305. AmiSilence();
  306. if (dmasound.soft.speed)
  307. period = amiga_colorclock/dmasound.soft.speed-1;
  308. else
  309. period = amiga_audio_min_period;
  310. dmasound.hard = dmasound.soft;
  311. dmasound.trans_write = &transAmiga;
  312. if (period < amiga_audio_min_period) {
  313. /* we would need to squeeze the sound, but we won't do that */
  314. period = amiga_audio_min_period;
  315. } else if (period > 65535) {
  316. period = 65535;
  317. }
  318. dmasound.hard.speed = amiga_colorclock/(period+1);
  319. for (i = 0; i < 4; i++)
  320. custom.aud[i].audper = period;
  321. amiga_audio_period = period;
  322. }
  323. static int AmiSetFormat(int format)
  324. {
  325. int size;
  326. /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
  327. switch (format) {
  328. case AFMT_QUERY:
  329. return dmasound.soft.format;
  330. case AFMT_MU_LAW:
  331. case AFMT_A_LAW:
  332. case AFMT_U8:
  333. case AFMT_S8:
  334. size = 8;
  335. break;
  336. case AFMT_S16_BE:
  337. case AFMT_U16_BE:
  338. case AFMT_S16_LE:
  339. case AFMT_U16_LE:
  340. size = 16;
  341. break;
  342. default: /* :-) */
  343. size = 8;
  344. format = AFMT_S8;
  345. }
  346. dmasound.soft.format = format;
  347. dmasound.soft.size = size;
  348. if (dmasound.minDev == SND_DEV_DSP) {
  349. dmasound.dsp.format = format;
  350. dmasound.dsp.size = dmasound.soft.size;
  351. }
  352. AmiInit();
  353. return format;
  354. }
  355. #define VOLUME_VOXWARE_TO_AMI(v) \
  356. (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
  357. #define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
  358. static int AmiSetVolume(int volume)
  359. {
  360. dmasound.volume_left = VOLUME_VOXWARE_TO_AMI(volume & 0xff);
  361. custom.aud[0].audvol = dmasound.volume_left;
  362. dmasound.volume_right = VOLUME_VOXWARE_TO_AMI((volume & 0xff00) >> 8);
  363. custom.aud[1].audvol = dmasound.volume_right;
  364. if (dmasound.hard.size == 16) {
  365. if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
  366. custom.aud[2].audvol = 1;
  367. custom.aud[3].audvol = 1;
  368. } else {
  369. custom.aud[2].audvol = 0;
  370. custom.aud[3].audvol = 0;
  371. }
  372. }
  373. return VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
  374. (VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
  375. }
  376. static int AmiSetTreble(int treble)
  377. {
  378. dmasound.treble = treble;
  379. if (treble < 50)
  380. ciaa.pra &= ~0x02;
  381. else
  382. ciaa.pra |= 0x02;
  383. return treble;
  384. }
  385. #define AMI_PLAY_LOADED 1
  386. #define AMI_PLAY_PLAYING 2
  387. #define AMI_PLAY_MASK 3
  388. static void AmiPlayNextFrame(int index)
  389. {
  390. u_char *start, *ch0, *ch1, *ch2, *ch3;
  391. u_long size;
  392. /* used by AmiPlay() if all doubts whether there really is something
  393. * to be played are already wiped out.
  394. */
  395. start = write_sq.buffers[write_sq.front];
  396. size = (write_sq.count == index ? write_sq.rear_size
  397. : write_sq.block_size)>>1;
  398. if (dmasound.hard.stereo) {
  399. ch0 = start;
  400. ch1 = start+write_sq_block_size_half;
  401. size >>= 1;
  402. } else {
  403. ch0 = start;
  404. ch1 = start;
  405. }
  406. disable_heartbeat();
  407. custom.aud[0].audvol = dmasound.volume_left;
  408. custom.aud[1].audvol = dmasound.volume_right;
  409. if (dmasound.hard.size == 8) {
  410. custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
  411. custom.aud[0].audlen = size;
  412. custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
  413. custom.aud[1].audlen = size;
  414. custom.dmacon = AMI_AUDIO_8;
  415. } else {
  416. size >>= 1;
  417. custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
  418. custom.aud[0].audlen = size;
  419. custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
  420. custom.aud[1].audlen = size;
  421. if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
  422. /* We can play pseudo 14-bit only with the maximum volume */
  423. ch3 = ch0+write_sq_block_size_quarter;
  424. ch2 = ch1+write_sq_block_size_quarter;
  425. custom.aud[2].audvol = 1; /* we are being affected by the beeps */
  426. custom.aud[3].audvol = 1; /* restoring volume here helps a bit */
  427. custom.aud[2].audlc = (u_short *)ZTWO_PADDR(ch2);
  428. custom.aud[2].audlen = size;
  429. custom.aud[3].audlc = (u_short *)ZTWO_PADDR(ch3);
  430. custom.aud[3].audlen = size;
  431. custom.dmacon = AMI_AUDIO_14;
  432. } else {
  433. custom.aud[2].audvol = 0;
  434. custom.aud[3].audvol = 0;
  435. custom.dmacon = AMI_AUDIO_8;
  436. }
  437. }
  438. write_sq.front = (write_sq.front+1) % write_sq.max_count;
  439. write_sq.active |= AMI_PLAY_LOADED;
  440. }
  441. static void AmiPlay(void)
  442. {
  443. int minframes = 1;
  444. custom.intena = IF_AUD0;
  445. if (write_sq.active & AMI_PLAY_LOADED) {
  446. /* There's already a frame loaded */
  447. custom.intena = IF_SETCLR | IF_AUD0;
  448. return;
  449. }
  450. if (write_sq.active & AMI_PLAY_PLAYING)
  451. /* Increase threshold: frame 1 is already being played */
  452. minframes = 2;
  453. if (write_sq.count < minframes) {
  454. /* Nothing to do */
  455. custom.intena = IF_SETCLR | IF_AUD0;
  456. return;
  457. }
  458. if (write_sq.count <= minframes &&
  459. write_sq.rear_size < write_sq.block_size && !write_sq.syncing) {
  460. /* hmmm, the only existing frame is not
  461. * yet filled and we're not syncing?
  462. */
  463. custom.intena = IF_SETCLR | IF_AUD0;
  464. return;
  465. }
  466. AmiPlayNextFrame(minframes);
  467. custom.intena = IF_SETCLR | IF_AUD0;
  468. }
  469. static irqreturn_t AmiInterrupt(int irq, void *dummy)
  470. {
  471. int minframes = 1;
  472. custom.intena = IF_AUD0;
  473. if (!write_sq.active) {
  474. /* Playing was interrupted and sq_reset() has already cleared
  475. * the sq variables, so better don't do anything here.
  476. */
  477. WAKE_UP(write_sq.sync_queue);
  478. return IRQ_HANDLED;
  479. }
  480. if (write_sq.active & AMI_PLAY_PLAYING) {
  481. /* We've just finished a frame */
  482. write_sq.count--;
  483. WAKE_UP(write_sq.action_queue);
  484. }
  485. if (write_sq.active & AMI_PLAY_LOADED)
  486. /* Increase threshold: frame 1 is already being played */
  487. minframes = 2;
  488. /* Shift the flags */
  489. write_sq.active = (write_sq.active<<1) & AMI_PLAY_MASK;
  490. if (!write_sq.active)
  491. /* No frame is playing, disable audio DMA */
  492. StopDMA();
  493. custom.intena = IF_SETCLR | IF_AUD0;
  494. if (write_sq.count >= minframes)
  495. /* Try to play the next frame */
  496. AmiPlay();
  497. if (!write_sq.active)
  498. /* Nothing to play anymore.
  499. Wake up a process waiting for audio output to drain. */
  500. WAKE_UP(write_sq.sync_queue);
  501. return IRQ_HANDLED;
  502. }
  503. /*** Mid level stuff *********************************************************/
  504. /*
  505. * /dev/mixer abstraction
  506. */
  507. static void __init AmiMixerInit(void)
  508. {
  509. dmasound.volume_left = 64;
  510. dmasound.volume_right = 64;
  511. custom.aud[0].audvol = dmasound.volume_left;
  512. custom.aud[3].audvol = 1; /* For pseudo 14bit */
  513. custom.aud[1].audvol = dmasound.volume_right;
  514. custom.aud[2].audvol = 1; /* For pseudo 14bit */
  515. dmasound.treble = 50;
  516. }
  517. static int AmiMixerIoctl(u_int cmd, u_long arg)
  518. {
  519. int data;
  520. switch (cmd) {
  521. case SOUND_MIXER_READ_DEVMASK:
  522. return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_TREBLE);
  523. case SOUND_MIXER_READ_RECMASK:
  524. return IOCTL_OUT(arg, 0);
  525. case SOUND_MIXER_READ_STEREODEVS:
  526. return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
  527. case SOUND_MIXER_READ_VOLUME:
  528. return IOCTL_OUT(arg,
  529. VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
  530. VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
  531. case SOUND_MIXER_WRITE_VOLUME:
  532. IOCTL_IN(arg, data);
  533. return IOCTL_OUT(arg, dmasound_set_volume(data));
  534. case SOUND_MIXER_READ_TREBLE:
  535. return IOCTL_OUT(arg, dmasound.treble);
  536. case SOUND_MIXER_WRITE_TREBLE:
  537. IOCTL_IN(arg, data);
  538. return IOCTL_OUT(arg, dmasound_set_treble(data));
  539. }
  540. return -EINVAL;
  541. }
  542. static int AmiWriteSqSetup(void)
  543. {
  544. write_sq_block_size_half = write_sq.block_size>>1;
  545. write_sq_block_size_quarter = write_sq_block_size_half>>1;
  546. return 0;
  547. }
  548. static int AmiStateInfo(char *buffer, size_t space)
  549. {
  550. int len = 0;
  551. len += sprintf(buffer+len, "\tsound.volume_left = %d [0...64]\n",
  552. dmasound.volume_left);
  553. len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n",
  554. dmasound.volume_right);
  555. if (len >= space) {
  556. printk(KERN_ERR "dmasound_paula: overlowed state buffer alloc.\n") ;
  557. len = space ;
  558. }
  559. return len;
  560. }
  561. /*** Machine definitions *****************************************************/
  562. static SETTINGS def_hard = {
  563. .format = AFMT_S8,
  564. .stereo = 0,
  565. .size = 8,
  566. .speed = 8000
  567. } ;
  568. static SETTINGS def_soft = {
  569. .format = AFMT_U8,
  570. .stereo = 0,
  571. .size = 8,
  572. .speed = 8000
  573. } ;
  574. static MACHINE machAmiga = {
  575. .name = "Amiga",
  576. .name2 = "AMIGA",
  577. .owner = THIS_MODULE,
  578. .dma_alloc = AmiAlloc,
  579. .dma_free = AmiFree,
  580. .irqinit = AmiIrqInit,
  581. #ifdef MODULE
  582. .irqcleanup = AmiIrqCleanUp,
  583. #endif /* MODULE */
  584. .init = AmiInit,
  585. .silence = AmiSilence,
  586. .setFormat = AmiSetFormat,
  587. .setVolume = AmiSetVolume,
  588. .setTreble = AmiSetTreble,
  589. .play = AmiPlay,
  590. .mixer_init = AmiMixerInit,
  591. .mixer_ioctl = AmiMixerIoctl,
  592. .write_sq_setup = AmiWriteSqSetup,
  593. .state_info = AmiStateInfo,
  594. .min_dsp_speed = 8000,
  595. .version = ((DMASOUND_PAULA_REVISION<<8) | DMASOUND_PAULA_EDITION),
  596. .hardware_afmts = (AFMT_S8 | AFMT_S16_BE), /* h'ware-supported formats *only* here */
  597. .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
  598. };
  599. /*** Config & Setup **********************************************************/
  600. int __init dmasound_paula_init(void)
  601. {
  602. int err;
  603. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) {
  604. if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40,
  605. "dmasound [Paula]"))
  606. return -EBUSY;
  607. dmasound.mach = machAmiga;
  608. dmasound.mach.default_hard = def_hard ;
  609. dmasound.mach.default_soft = def_soft ;
  610. err = dmasound_init();
  611. if (err)
  612. release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
  613. return err;
  614. } else
  615. return -ENODEV;
  616. }
  617. static void __exit dmasound_paula_cleanup(void)
  618. {
  619. dmasound_deinit();
  620. release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
  621. }
  622. module_init(dmasound_paula_init);
  623. module_exit(dmasound_paula_cleanup);
  624. MODULE_LICENSE("GPL");