amisound.c 2.7 KB

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