amisound.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /*
  24. * The minimum period for audio may be modified by the frame buffer
  25. * device since it depends on htotal (for OCS/ECS/AGA)
  26. */
  27. volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
  28. #define MAX_PERIOD (65535)
  29. /*
  30. * Current period (set by dmasound.c)
  31. */
  32. unsigned short amiga_audio_period = MAX_PERIOD;
  33. static unsigned long clock_constant;
  34. void __init amiga_init_sound(void)
  35. {
  36. static struct resource beep_res = { .name = "Beep" };
  37. snd_data = amiga_chip_alloc_res(sizeof(sine_data), &beep_res);
  38. if (!snd_data) {
  39. printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
  40. return;
  41. }
  42. memcpy (snd_data, sine_data, sizeof(sine_data));
  43. /* setup divisor */
  44. clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
  45. /* without amifb, turn video off and enable high quality sound */
  46. #ifndef CONFIG_FB_AMIGA
  47. amifb_video_off();
  48. #endif
  49. }
  50. static void nosound( unsigned long ignored );
  51. static struct timer_list sound_timer = TIMER_INITIALIZER(nosound, 0, 0);
  52. void amiga_mksound( unsigned int hz, unsigned int ticks )
  53. {
  54. unsigned long flags;
  55. if (!snd_data)
  56. return;
  57. local_irq_save(flags);
  58. del_timer( &sound_timer );
  59. if (hz > 20 && hz < 32767) {
  60. unsigned long period = (clock_constant / hz);
  61. if (period < amiga_audio_min_period)
  62. period = amiga_audio_min_period;
  63. if (period > MAX_PERIOD)
  64. period = MAX_PERIOD;
  65. /* setup pointer to data, period, length and volume */
  66. custom.aud[2].audlc = snd_data;
  67. custom.aud[2].audlen = sizeof(sine_data)/2;
  68. custom.aud[2].audper = (unsigned short)period;
  69. custom.aud[2].audvol = 32; /* 50% of maxvol */
  70. if (ticks) {
  71. sound_timer.expires = jiffies + ticks;
  72. add_timer( &sound_timer );
  73. }
  74. /* turn on DMA for audio channel 2 */
  75. custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
  76. } else
  77. nosound( 0 );
  78. local_irq_restore(flags);
  79. }
  80. static void nosound( unsigned long ignored )
  81. {
  82. /* turn off DMA for audio channel 2 */
  83. custom.dmacon = DMAF_AUD2;
  84. /* restore period to previous value after beeping */
  85. custom.aud[2].audper = amiga_audio_period;
  86. }