dmasound_paula.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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/config.h>
  18. #include <linux/mm.h>
  19. #include <linux/init.h>
  20. #include <linux/ioport.h>
  21. #include <linux/soundcard.h>
  22. #include <linux/interrupt.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/setup.h>
  25. #include <asm/amigahw.h>
  26. #include <asm/amigaints.h>
  27. #include <asm/machdep.h>
  28. #include "dmasound.h"
  29. #define DMASOUND_PAULA_REVISION 0
  30. #define DMASOUND_PAULA_EDITION 4
  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, int 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, struct pt_regs *fp);
  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 *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 *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 *userPtr, size_t userCount, \
  200. u_char frame[], ssize_t *frameUsed, \
  201. ssize_t frameLeft) \
  202. { \
  203. ssize_t count, used; \
  204. u_short data; \
  205. \
  206. if (!dmasound.soft.stereo) { \
  207. u_char *high = &frame[*frameUsed>>1]; \
  208. u_char *low = high+write_sq_block_size_half; \
  209. count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
  210. used = count*2; \
  211. while (count > 0) { \
  212. if (get_user(data, ((u_short *)userPtr)++)) \
  213. return -EFAULT; \
  214. data = convsample(data); \
  215. *high++ = data>>8; \
  216. *low++ = (data>>2) & 0x3f; \
  217. count--; \
  218. } \
  219. } else { \
  220. u_char *lefth = &frame[*frameUsed>>2]; \
  221. u_char *leftl = lefth+write_sq_block_size_quarter; \
  222. u_char *righth = lefth+write_sq_block_size_half; \
  223. u_char *rightl = righth+write_sq_block_size_quarter; \
  224. count = min_t(size_t, userCount, frameLeft)>>2 & ~1; \
  225. used = count*4; \
  226. while (count > 0) { \
  227. if (get_user(data, ((u_short *)userPtr)++)) \
  228. return -EFAULT; \
  229. data = convsample(data); \
  230. *lefth++ = data>>8; \
  231. *leftl++ = (data>>2) & 0x3f; \
  232. if (get_user(data, ((u_short *)userPtr)++)) \
  233. return -EFAULT; \
  234. data = convsample(data); \
  235. *righth++ = data>>8; \
  236. *rightl++ = (data>>2) & 0x3f; \
  237. count--; \
  238. } \
  239. } \
  240. *frameUsed += used; \
  241. return used; \
  242. }
  243. #define AMI_CT_S16BE(x) (x)
  244. #define AMI_CT_U16BE(x) ((x) ^ 0x8000)
  245. #define AMI_CT_S16LE(x) (le2be16((x)))
  246. #define AMI_CT_U16LE(x) (le2be16((x)) ^ 0x8000)
  247. GENERATE_AMI_CT_16(ami_ct_s16be, AMI_CT_S16BE)
  248. GENERATE_AMI_CT_16(ami_ct_u16be, AMI_CT_U16BE)
  249. GENERATE_AMI_CT_16(ami_ct_s16le, AMI_CT_S16LE)
  250. GENERATE_AMI_CT_16(ami_ct_u16le, AMI_CT_U16LE)
  251. static TRANS transAmiga = {
  252. .ct_ulaw = ami_ct_ulaw,
  253. .ct_alaw = ami_ct_alaw,
  254. .ct_s8 = ami_ct_s8,
  255. .ct_u8 = ami_ct_u8,
  256. .ct_s16be = ami_ct_s16be,
  257. .ct_u16be = ami_ct_u16be,
  258. .ct_s16le = ami_ct_s16le,
  259. .ct_u16le = ami_ct_u16le,
  260. };
  261. /*** Low level stuff *********************************************************/
  262. static inline void StopDMA(void)
  263. {
  264. custom.aud[0].audvol = custom.aud[1].audvol = 0;
  265. custom.aud[2].audvol = custom.aud[3].audvol = 0;
  266. custom.dmacon = AMI_AUDIO_OFF;
  267. enable_heartbeat();
  268. }
  269. static void *AmiAlloc(unsigned int size, int flags)
  270. {
  271. return amiga_chip_alloc((long)size, "dmasound [Paula]");
  272. }
  273. static void AmiFree(void *obj, unsigned int size)
  274. {
  275. amiga_chip_free (obj);
  276. }
  277. static int __init AmiIrqInit(void)
  278. {
  279. /* turn off DMA for audio channels */
  280. StopDMA();
  281. /* Register interrupt handler. */
  282. if (request_irq(IRQ_AMIGA_AUD0, AmiInterrupt, 0, "DMA sound",
  283. AmiInterrupt))
  284. return 0;
  285. return 1;
  286. }
  287. #ifdef MODULE
  288. static void AmiIrqCleanUp(void)
  289. {
  290. /* turn off DMA for audio channels */
  291. StopDMA();
  292. /* release the interrupt */
  293. free_irq(IRQ_AMIGA_AUD0, AmiInterrupt);
  294. }
  295. #endif /* MODULE */
  296. static void AmiSilence(void)
  297. {
  298. /* turn off DMA for audio channels */
  299. StopDMA();
  300. }
  301. static void AmiInit(void)
  302. {
  303. int period, i;
  304. AmiSilence();
  305. if (dmasound.soft.speed)
  306. period = amiga_colorclock/dmasound.soft.speed-1;
  307. else
  308. period = amiga_audio_min_period;
  309. dmasound.hard = dmasound.soft;
  310. dmasound.trans_write = &transAmiga;
  311. if (period < amiga_audio_min_period) {
  312. /* we would need to squeeze the sound, but we won't do that */
  313. period = amiga_audio_min_period;
  314. } else if (period > 65535) {
  315. period = 65535;
  316. }
  317. dmasound.hard.speed = amiga_colorclock/(period+1);
  318. for (i = 0; i < 4; i++)
  319. custom.aud[i].audper = period;
  320. amiga_audio_period = period;
  321. }
  322. static int AmiSetFormat(int format)
  323. {
  324. int size;
  325. /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
  326. switch (format) {
  327. case AFMT_QUERY:
  328. return dmasound.soft.format;
  329. case AFMT_MU_LAW:
  330. case AFMT_A_LAW:
  331. case AFMT_U8:
  332. case AFMT_S8:
  333. size = 8;
  334. break;
  335. case AFMT_S16_BE:
  336. case AFMT_U16_BE:
  337. case AFMT_S16_LE:
  338. case AFMT_U16_LE:
  339. size = 16;
  340. break;
  341. default: /* :-) */
  342. size = 8;
  343. format = AFMT_S8;
  344. }
  345. dmasound.soft.format = format;
  346. dmasound.soft.size = size;
  347. if (dmasound.minDev == SND_DEV_DSP) {
  348. dmasound.dsp.format = format;
  349. dmasound.dsp.size = dmasound.soft.size;
  350. }
  351. AmiInit();
  352. return format;
  353. }
  354. #define VOLUME_VOXWARE_TO_AMI(v) \
  355. (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
  356. #define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
  357. static int AmiSetVolume(int volume)
  358. {
  359. dmasound.volume_left = VOLUME_VOXWARE_TO_AMI(volume & 0xff);
  360. custom.aud[0].audvol = dmasound.volume_left;
  361. dmasound.volume_right = VOLUME_VOXWARE_TO_AMI((volume & 0xff00) >> 8);
  362. custom.aud[1].audvol = dmasound.volume_right;
  363. if (dmasound.hard.size == 16) {
  364. if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
  365. custom.aud[2].audvol = 1;
  366. custom.aud[3].audvol = 1;
  367. } else {
  368. custom.aud[2].audvol = 0;
  369. custom.aud[3].audvol = 0;
  370. }
  371. }
  372. return VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
  373. (VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
  374. }
  375. static int AmiSetTreble(int treble)
  376. {
  377. dmasound.treble = treble;
  378. if (treble < 50)
  379. ciaa.pra &= ~0x02;
  380. else
  381. ciaa.pra |= 0x02;
  382. return treble;
  383. }
  384. #define AMI_PLAY_LOADED 1
  385. #define AMI_PLAY_PLAYING 2
  386. #define AMI_PLAY_MASK 3
  387. static void AmiPlayNextFrame(int index)
  388. {
  389. u_char *start, *ch0, *ch1, *ch2, *ch3;
  390. u_long size;
  391. /* used by AmiPlay() if all doubts whether there really is something
  392. * to be played are already wiped out.
  393. */
  394. start = write_sq.buffers[write_sq.front];
  395. size = (write_sq.count == index ? write_sq.rear_size
  396. : write_sq.block_size)>>1;
  397. if (dmasound.hard.stereo) {
  398. ch0 = start;
  399. ch1 = start+write_sq_block_size_half;
  400. size >>= 1;
  401. } else {
  402. ch0 = start;
  403. ch1 = start;
  404. }
  405. disable_heartbeat();
  406. custom.aud[0].audvol = dmasound.volume_left;
  407. custom.aud[1].audvol = dmasound.volume_right;
  408. if (dmasound.hard.size == 8) {
  409. custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
  410. custom.aud[0].audlen = size;
  411. custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
  412. custom.aud[1].audlen = size;
  413. custom.dmacon = AMI_AUDIO_8;
  414. } else {
  415. size >>= 1;
  416. custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
  417. custom.aud[0].audlen = size;
  418. custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
  419. custom.aud[1].audlen = size;
  420. if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
  421. /* We can play pseudo 14-bit only with the maximum volume */
  422. ch3 = ch0+write_sq_block_size_quarter;
  423. ch2 = ch1+write_sq_block_size_quarter;
  424. custom.aud[2].audvol = 1; /* we are being affected by the beeps */
  425. custom.aud[3].audvol = 1; /* restoring volume here helps a bit */
  426. custom.aud[2].audlc = (u_short *)ZTWO_PADDR(ch2);
  427. custom.aud[2].audlen = size;
  428. custom.aud[3].audlc = (u_short *)ZTWO_PADDR(ch3);
  429. custom.aud[3].audlen = size;
  430. custom.dmacon = AMI_AUDIO_14;
  431. } else {
  432. custom.aud[2].audvol = 0;
  433. custom.aud[3].audvol = 0;
  434. custom.dmacon = AMI_AUDIO_8;
  435. }
  436. }
  437. write_sq.front = (write_sq.front+1) % write_sq.max_count;
  438. write_sq.active |= AMI_PLAY_LOADED;
  439. }
  440. static void AmiPlay(void)
  441. {
  442. int minframes = 1;
  443. custom.intena = IF_AUD0;
  444. if (write_sq.active & AMI_PLAY_LOADED) {
  445. /* There's already a frame loaded */
  446. custom.intena = IF_SETCLR | IF_AUD0;
  447. return;
  448. }
  449. if (write_sq.active & AMI_PLAY_PLAYING)
  450. /* Increase threshold: frame 1 is already being played */
  451. minframes = 2;
  452. if (write_sq.count < minframes) {
  453. /* Nothing to do */
  454. custom.intena = IF_SETCLR | IF_AUD0;
  455. return;
  456. }
  457. if (write_sq.count <= minframes &&
  458. write_sq.rear_size < write_sq.block_size && !write_sq.syncing) {
  459. /* hmmm, the only existing frame is not
  460. * yet filled and we're not syncing?
  461. */
  462. custom.intena = IF_SETCLR | IF_AUD0;
  463. return;
  464. }
  465. AmiPlayNextFrame(minframes);
  466. custom.intena = IF_SETCLR | IF_AUD0;
  467. }
  468. static irqreturn_t AmiInterrupt(int irq, void *dummy, struct pt_regs *fp)
  469. {
  470. int minframes = 1;
  471. custom.intena = IF_AUD0;
  472. if (!write_sq.active) {
  473. /* Playing was interrupted and sq_reset() has already cleared
  474. * the sq variables, so better don't do anything here.
  475. */
  476. WAKE_UP(write_sq.sync_queue);
  477. return IRQ_HANDLED;
  478. }
  479. if (write_sq.active & AMI_PLAY_PLAYING) {
  480. /* We've just finished a frame */
  481. write_sq.count--;
  482. WAKE_UP(write_sq.action_queue);
  483. }
  484. if (write_sq.active & AMI_PLAY_LOADED)
  485. /* Increase threshold: frame 1 is already being played */
  486. minframes = 2;
  487. /* Shift the flags */
  488. write_sq.active = (write_sq.active<<1) & AMI_PLAY_MASK;
  489. if (!write_sq.active)
  490. /* No frame is playing, disable audio DMA */
  491. StopDMA();
  492. custom.intena = IF_SETCLR | IF_AUD0;
  493. if (write_sq.count >= minframes)
  494. /* Try to play the next frame */
  495. AmiPlay();
  496. if (!write_sq.active)
  497. /* Nothing to play anymore.
  498. Wake up a process waiting for audio output to drain. */
  499. WAKE_UP(write_sq.sync_queue);
  500. return IRQ_HANDLED;
  501. }
  502. /*** Mid level stuff *********************************************************/
  503. /*
  504. * /dev/mixer abstraction
  505. */
  506. static void __init AmiMixerInit(void)
  507. {
  508. dmasound.volume_left = 64;
  509. dmasound.volume_right = 64;
  510. custom.aud[0].audvol = dmasound.volume_left;
  511. custom.aud[3].audvol = 1; /* For pseudo 14bit */
  512. custom.aud[1].audvol = dmasound.volume_right;
  513. custom.aud[2].audvol = 1; /* For pseudo 14bit */
  514. dmasound.treble = 50;
  515. }
  516. static int AmiMixerIoctl(u_int cmd, u_long arg)
  517. {
  518. int data;
  519. switch (cmd) {
  520. case SOUND_MIXER_READ_DEVMASK:
  521. return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_TREBLE);
  522. case SOUND_MIXER_READ_RECMASK:
  523. return IOCTL_OUT(arg, 0);
  524. case SOUND_MIXER_READ_STEREODEVS:
  525. return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
  526. case SOUND_MIXER_READ_VOLUME:
  527. return IOCTL_OUT(arg,
  528. VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
  529. VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
  530. case SOUND_MIXER_WRITE_VOLUME:
  531. IOCTL_IN(arg, data);
  532. return IOCTL_OUT(arg, dmasound_set_volume(data));
  533. case SOUND_MIXER_READ_TREBLE:
  534. return IOCTL_OUT(arg, dmasound.treble);
  535. case SOUND_MIXER_WRITE_TREBLE:
  536. IOCTL_IN(arg, data);
  537. return IOCTL_OUT(arg, dmasound_set_treble(data));
  538. }
  539. return -EINVAL;
  540. }
  541. static int AmiWriteSqSetup(void)
  542. {
  543. write_sq_block_size_half = write_sq.block_size>>1;
  544. write_sq_block_size_quarter = write_sq_block_size_half>>1;
  545. return 0;
  546. }
  547. static int AmiStateInfo(char *buffer, size_t space)
  548. {
  549. int len = 0;
  550. len += sprintf(buffer+len, "\tsound.volume_left = %d [0...64]\n",
  551. dmasound.volume_left);
  552. len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n",
  553. dmasound.volume_right);
  554. if (len >= space) {
  555. printk(KERN_ERR "dmasound_paula: overlowed state buffer alloc.\n") ;
  556. len = space ;
  557. }
  558. return len;
  559. }
  560. /*** Machine definitions *****************************************************/
  561. static SETTINGS def_hard = {
  562. .format = AFMT_S8,
  563. .stereo = 0,
  564. .size = 8,
  565. .speed = 8000
  566. } ;
  567. static SETTINGS def_soft = {
  568. .format = AFMT_U8,
  569. .stereo = 0,
  570. .size = 8,
  571. .speed = 8000
  572. } ;
  573. static MACHINE machAmiga = {
  574. .name = "Amiga",
  575. .name2 = "AMIGA",
  576. .owner = THIS_MODULE,
  577. .dma_alloc = AmiAlloc,
  578. .dma_free = AmiFree,
  579. .irqinit = AmiIrqInit,
  580. #ifdef MODULE
  581. .irqcleanup = AmiIrqCleanUp,
  582. #endif /* MODULE */
  583. .init = AmiInit,
  584. .silence = AmiSilence,
  585. .setFormat = AmiSetFormat,
  586. .setVolume = AmiSetVolume,
  587. .setTreble = AmiSetTreble,
  588. .play = AmiPlay,
  589. .mixer_init = AmiMixerInit,
  590. .mixer_ioctl = AmiMixerIoctl,
  591. .write_sq_setup = AmiWriteSqSetup,
  592. .state_info = AmiStateInfo,
  593. .min_dsp_speed = 8000,
  594. .version = ((DMASOUND_PAULA_REVISION<<8) | DMASOUND_PAULA_EDITION),
  595. .hardware_afmts = (AFMT_S8 | AFMT_S16_BE), /* h'ware-supported formats *only* here */
  596. .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
  597. };
  598. /*** Config & Setup **********************************************************/
  599. int __init dmasound_paula_init(void)
  600. {
  601. int err;
  602. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) {
  603. if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40,
  604. "dmasound [Paula]"))
  605. return -EBUSY;
  606. dmasound.mach = machAmiga;
  607. dmasound.mach.default_hard = def_hard ;
  608. dmasound.mach.default_soft = def_soft ;
  609. err = dmasound_init();
  610. if (err)
  611. release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
  612. return err;
  613. } else
  614. return -ENODEV;
  615. }
  616. static void __exit dmasound_paula_cleanup(void)
  617. {
  618. dmasound_deinit();
  619. release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
  620. }
  621. module_init(dmasound_paula_init);
  622. module_exit(dmasound_paula_cleanup);
  623. MODULE_LICENSE("GPL");