dmasound_paula.c 19 KB

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