amisound.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * linux/arch/m68k/amiga/amisound.c
  3. *
  4. * amiga sound driver for Linux/m68k
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/config.h>
  11. #include <linux/jiffies.h>
  12. #include <linux/timer.h>
  13. #include <linux/init.h>
  14. #include <linux/string.h>
  15. #include <asm/system.h>
  16. #include <asm/amigahw.h>
  17. static unsigned short *snd_data;
  18. static const signed char sine_data[] = {
  19. 0, 39, 75, 103, 121, 127, 121, 103, 75, 39,
  20. 0, -39, -75, -103, -121, -127, -121, -103, -75, -39
  21. };
  22. #define DATA_SIZE (sizeof(sine_data)/sizeof(sine_data[0]))
  23. #define custom amiga_custom
  24. /*
  25. * The minimum period for audio may be modified by the frame buffer
  26. * device since it depends on htotal (for OCS/ECS/AGA)
  27. */
  28. volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
  29. #define MAX_PERIOD (65535)
  30. /*
  31. * Current period (set by dmasound.c)
  32. */
  33. unsigned short amiga_audio_period = MAX_PERIOD;
  34. static unsigned long clock_constant;
  35. void __init amiga_init_sound(void)
  36. {
  37. static struct resource beep_res = { .name = "Beep" };
  38. snd_data = amiga_chip_alloc_res(sizeof(sine_data), &beep_res);
  39. if (!snd_data) {
  40. printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
  41. return;
  42. }
  43. memcpy (snd_data, sine_data, sizeof(sine_data));
  44. /* setup divisor */
  45. clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
  46. /* without amifb, turn video off and enable high quality sound */
  47. #ifndef CONFIG_FB_AMIGA
  48. amifb_video_off();
  49. #endif
  50. }
  51. static void nosound( unsigned long ignored );
  52. static DEFINE_TIMER(sound_timer, nosound, 0, 0);
  53. void amiga_mksound( unsigned int hz, unsigned int ticks )
  54. {
  55. unsigned long flags;
  56. if (!snd_data)
  57. return;
  58. local_irq_save(flags);
  59. del_timer( &sound_timer );
  60. if (hz > 20 && hz < 32767) {
  61. unsigned long period = (clock_constant / hz);
  62. if (period < amiga_audio_min_period)
  63. period = amiga_audio_min_period;
  64. if (period > MAX_PERIOD)
  65. period = MAX_PERIOD;
  66. /* setup pointer to data, period, length and volume */
  67. custom.aud[2].audlc = snd_data;
  68. custom.aud[2].audlen = sizeof(sine_data)/2;
  69. custom.aud[2].audper = (unsigned short)period;
  70. custom.aud[2].audvol = 32; /* 50% of maxvol */
  71. if (ticks) {
  72. sound_timer.expires = jiffies + ticks;
  73. add_timer( &sound_timer );
  74. }
  75. /* turn on DMA for audio channel 2 */
  76. custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
  77. } else
  78. nosound( 0 );
  79. local_irq_restore(flags);
  80. }
  81. static void nosound( unsigned long ignored )
  82. {
  83. /* turn off DMA for audio channel 2 */
  84. custom.dmacon = DMAF_AUD2;
  85. /* restore period to previous value after beeping */
  86. custom.aud[2].audper = amiga_audio_period;
  87. }