dmasound_paula.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/sound/oss/dmasound/dmasound_paula.c
  4. *
  5. * Amiga `Paula' DMA Sound Driver
  6. *
  7. * See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
  8. * prior to 28/01/2001
  9. *
  10. * 28/01/2001 [0.1] Iain Sandoe
  11. * - added versioning
  12. * - put in and populated the hardware_afmts field.
  13. * [0.2] - put in SNDCTL_DSP_GETCAPS value.
  14. * [0.3] - put in constraint on state buffer usage.
  15. * [0.4] - put in default hard/soft settings
  16. */
  17. #include <linux/module.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 <linux/platform_device.h>
  24. #include <linux/uaccess.h>
  25. #include <asm/setup.h>
  26. #include <asm/amigahw.h>
  27. #include <asm/amigaints.h>
  28. #include <asm/machdep.h>
  29. #include "dmasound.h"
  30. #define DMASOUND_PAULA_REVISION 0
  31. #define DMASOUND_PAULA_EDITION 4
  32. #define custom amiga_custom
  33. /*
  34. * The minimum period for audio depends on htotal (for OCS/ECS/AGA)
  35. * (Imported from arch/m68k/amiga/amisound.c)
  36. */
  37. extern volatile u_short amiga_audio_min_period;
  38. /*
  39. * amiga_mksound() should be able to restore the period after beeping
  40. * (Imported from arch/m68k/amiga/amisound.c)
  41. */
  42. extern u_short amiga_audio_period;
  43. /*
  44. * Audio DMA masks
  45. */
  46. #define AMI_AUDIO_OFF (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
  47. #define AMI_AUDIO_8 (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
  48. #define AMI_AUDIO_14 (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
  49. /*
  50. * Helper pointers for 16(14)-bit sound
  51. */
  52. static int write_sq_block_size_half, write_sq_block_size_quarter;
  53. /*** Low level stuff *********************************************************/
  54. static void *AmiAlloc(unsigned int size, gfp_t flags);
  55. static void AmiFree(void *obj, unsigned int size);
  56. static int AmiIrqInit(void);
  57. #ifdef MODULE
  58. static void AmiIrqCleanUp(void);
  59. #endif
  60. static void AmiSilence(void);
  61. static void AmiInit(void);
  62. static int AmiSetFormat(int format);
  63. static int AmiSetVolume(int volume);
  64. static int AmiSetTreble(int treble);
  65. static void AmiPlayNextFrame(int index);
  66. static void AmiPlay(void);
  67. static irqreturn_t AmiInterrupt(int irq, void *dummy);
  68. #ifdef CONFIG_HEARTBEAT
  69. /*
  70. * Heartbeat interferes with sound since the 7 kHz low-pass filter and the
  71. * power LED are controlled by the same line.
  72. */
  73. static void (*saved_heartbeat)(int) = NULL;
  74. static inline void disable_heartbeat(void)
  75. {
  76. if (mach_heartbeat) {
  77. saved_heartbeat = mach_heartbeat;
  78. mach_heartbeat = NULL;
  79. }
  80. AmiSetTreble(dmasound.treble);
  81. }
  82. static inline void enable_heartbeat(void)
  83. {
  84. if (saved_heartbeat)
  85. mach_heartbeat = saved_heartbeat;
  86. }
  87. #else /* !CONFIG_HEARTBEAT */
  88. #define disable_heartbeat() do { } while (0)
  89. #define enable_heartbeat() do { } while (0)
  90. #endif /* !CONFIG_HEARTBEAT */
  91. /*** Mid level stuff *********************************************************/
  92. static void AmiMixerInit(void);
  93. static int AmiMixerIoctl(u_int cmd, u_long arg);
  94. static int AmiWriteSqSetup(void);
  95. static int AmiStateInfo(char *buffer, size_t space);
  96. /*** Translations ************************************************************/
  97. /* ++TeSche: radically changed for new expanding purposes...
  98. *
  99. * These two routines now deal with copying/expanding/translating the samples
  100. * from user space into our buffer at the right frequency. They take care about
  101. * how much data there's actually to read, how much buffer space there is and
  102. * to convert samples into the right frequency/encoding. They will only work on
  103. * complete samples so it may happen they leave some bytes in the input stream
  104. * if the user didn't write a multiple of the current sample size. They both
  105. * return the number of bytes they've used from both streams so you may detect
  106. * such a situation. Luckily all programs should be able to cope with that.
  107. *
  108. * I think I've optimized anything as far as one can do in plain C, all
  109. * variables should fit in registers and the loops are really short. There's
  110. * one loop for every possible situation. Writing a more generalized and thus
  111. * parameterized loop would only produce slower code. Feel free to optimize
  112. * this in assembler if you like. :)
  113. *
  114. * I think these routines belong here because they're not yet really hardware
  115. * independent, especially the fact that the Falcon can play 16bit samples
  116. * only in stereo is hardcoded in both of them!
  117. *
  118. * ++geert: split in even more functions (one per format)
  119. */
  120. /*
  121. * Native format
  122. */
  123. static ssize_t ami_ct_s8(const u_char __user *userPtr, size_t userCount,
  124. u_char frame[], ssize_t *frameUsed, ssize_t frameLeft)
  125. {
  126. ssize_t count, used;
  127. if (!dmasound.soft.stereo) {
  128. void *p = &frame[*frameUsed];
  129. count = min_t(unsigned long, userCount, frameLeft) & ~1;
  130. used = count;
  131. if (copy_from_user(p, userPtr, count))
  132. return -EFAULT;
  133. } else {
  134. u_char *left = &frame[*frameUsed>>1];
  135. u_char *right = left+write_sq_block_size_half;
  136. count = min_t(unsigned long, userCount, frameLeft)>>1 & ~1;
  137. used = count*2;
  138. while (count > 0) {
  139. if (get_user(*left++, userPtr++)
  140. || get_user(*right++, userPtr++))
  141. return -EFAULT;
  142. count--;
  143. }
  144. }
  145. *frameUsed += used;
  146. return used;
  147. }
  148. /*
  149. * Copy and convert 8 bit data
  150. */
  151. #define GENERATE_AMI_CT8(funcname, convsample) \
  152. static ssize_t funcname(const u_char __user *userPtr, size_t userCount, \
  153. u_char frame[], ssize_t *frameUsed, \
  154. ssize_t frameLeft) \
  155. { \
  156. ssize_t count, used; \
  157. \
  158. if (!dmasound.soft.stereo) { \
  159. u_char *p = &frame[*frameUsed]; \
  160. count = min_t(size_t, userCount, frameLeft) & ~1; \
  161. used = count; \
  162. while (count > 0) { \
  163. u_char data; \
  164. if (get_user(data, userPtr++)) \
  165. return -EFAULT; \
  166. *p++ = convsample(data); \
  167. count--; \
  168. } \
  169. } else { \
  170. u_char *left = &frame[*frameUsed>>1]; \
  171. u_char *right = left+write_sq_block_size_half; \
  172. count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
  173. used = count*2; \
  174. while (count > 0) { \
  175. u_char data; \
  176. if (get_user(data, userPtr++)) \
  177. return -EFAULT; \
  178. *left++ = convsample(data); \
  179. if (get_user(data, userPtr++)) \
  180. return -EFAULT; \
  181. *right++ = convsample(data); \
  182. count--; \
  183. } \
  184. } \
  185. *frameUsed += used; \
  186. return used; \
  187. }
  188. #define AMI_CT_ULAW(x) (dmasound_ulaw2dma8[(x)])
  189. #define AMI_CT_ALAW(x) (dmasound_alaw2dma8[(x)])
  190. #define AMI_CT_U8(x) ((x) ^ 0x80)
  191. GENERATE_AMI_CT8(ami_ct_ulaw, AMI_CT_ULAW)
  192. GENERATE_AMI_CT8(ami_ct_alaw, AMI_CT_ALAW)
  193. GENERATE_AMI_CT8(ami_ct_u8, AMI_CT_U8)
  194. /*
  195. * Copy and convert 16 bit data
  196. */
  197. #define GENERATE_AMI_CT_16(funcname, convsample) \
  198. static ssize_t funcname(const u_char __user *userPtr, size_t userCount, \
  199. u_char frame[], ssize_t *frameUsed, \
  200. ssize_t frameLeft) \
  201. { \
  202. const u_short __user *ptr = (const u_short __user *)userPtr; \
  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, ptr++)) \
  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, ptr++)) \
  228. return -EFAULT; \
  229. data = convsample(data); \
  230. *lefth++ = data>>8; \
  231. *leftl++ = (data>>2) & 0x3f; \
  232. if (get_user(data, ptr++)) \
  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, gfp_t 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)
  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: overflowed 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. static int __init amiga_audio_probe(struct platform_device *pdev)
  600. {
  601. dmasound.mach = machAmiga;
  602. dmasound.mach.default_hard = def_hard ;
  603. dmasound.mach.default_soft = def_soft ;
  604. return dmasound_init();
  605. }
  606. static int __exit amiga_audio_remove(struct platform_device *pdev)
  607. {
  608. dmasound_deinit();
  609. return 0;
  610. }
  611. static struct platform_driver amiga_audio_driver = {
  612. .remove = __exit_p(amiga_audio_remove),
  613. .driver = {
  614. .name = "amiga-audio",
  615. },
  616. };
  617. module_platform_driver_probe(amiga_audio_driver, amiga_audio_probe);
  618. MODULE_LICENSE("GPL");
  619. MODULE_ALIAS("platform:amiga-audio");