amisound.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/jiffies.h>
  11. #include <linux/timer.h>
  12. #include <linux/init.h>
  13. #include <linux/string.h>
  14. #include <linux/module.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 ARRAY_SIZE(sine_data)
  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. EXPORT_SYMBOL(amiga_audio_min_period);
  30. #define MAX_PERIOD (65535)
  31. /*
  32. * Current period (set by dmasound.c)
  33. */
  34. unsigned short amiga_audio_period = MAX_PERIOD;
  35. EXPORT_SYMBOL(amiga_audio_period);
  36. static unsigned long clock_constant;
  37. void __init amiga_init_sound(void)
  38. {
  39. static struct resource beep_res = { .name = "Beep" };
  40. snd_data = amiga_chip_alloc_res(sizeof(sine_data), &beep_res);
  41. if (!snd_data) {
  42. printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
  43. return;
  44. }
  45. memcpy (snd_data, sine_data, sizeof(sine_data));
  46. /* setup divisor */
  47. clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
  48. /* without amifb, turn video off and enable high quality sound */
  49. #ifndef CONFIG_FB_AMIGA
  50. amifb_video_off();
  51. #endif
  52. }
  53. static void nosound( unsigned long ignored );
  54. static DEFINE_TIMER(sound_timer, nosound, 0, 0);
  55. void amiga_mksound( unsigned int hz, unsigned int ticks )
  56. {
  57. unsigned long flags;
  58. if (!snd_data)
  59. return;
  60. local_irq_save(flags);
  61. del_timer( &sound_timer );
  62. if (hz > 20 && hz < 32767) {
  63. unsigned long period = (clock_constant / hz);
  64. if (period < amiga_audio_min_period)
  65. period = amiga_audio_min_period;
  66. if (period > MAX_PERIOD)
  67. period = MAX_PERIOD;
  68. /* setup pointer to data, period, length and volume */
  69. custom.aud[2].audlc = snd_data;
  70. custom.aud[2].audlen = sizeof(sine_data)/2;
  71. custom.aud[2].audper = (unsigned short)period;
  72. custom.aud[2].audvol = 32; /* 50% of maxvol */
  73. if (ticks) {
  74. sound_timer.expires = jiffies + ticks;
  75. add_timer( &sound_timer );
  76. }
  77. /* turn on DMA for audio channel 2 */
  78. custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
  79. } else
  80. nosound( 0 );
  81. local_irq_restore(flags);
  82. }
  83. static void nosound( unsigned long ignored )
  84. {
  85. /* turn off DMA for audio channel 2 */
  86. custom.dmacon = DMAF_AUD2;
  87. /* restore period to previous value after beeping */
  88. custom.aud[2].audper = amiga_audio_period;
  89. }