atasound.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * linux/arch/m68k/atari/atasound.c
  3. *
  4. * ++Geert: Moved almost all stuff to linux/drivers/sound/
  5. *
  6. * The author of atari_nosound, atari_mksound and atari_microwire_cmd is
  7. * unknown. (++roman: That's me... :-)
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive
  11. * for more details.
  12. *
  13. * 1998-05-31 ++andreas: atari_mksound rewritten to always use the envelope,
  14. * no timer, atari_nosound removed.
  15. *
  16. */
  17. #include <linux/sched.h>
  18. #include <linux/timer.h>
  19. #include <linux/major.h>
  20. #include <linux/fcntl.h>
  21. #include <linux/errno.h>
  22. #include <linux/mm.h>
  23. #include <linux/module.h>
  24. #include <asm/atarihw.h>
  25. #include <asm/irq.h>
  26. #include <asm/atariints.h>
  27. /*
  28. * stuff from the old atasound.c
  29. */
  30. void atari_microwire_cmd (int cmd)
  31. {
  32. tt_microwire.mask = 0x7ff;
  33. tt_microwire.data = MW_LM1992_ADDR | cmd;
  34. /* Busy wait for data being completely sent :-( */
  35. while( tt_microwire.mask != 0x7ff)
  36. ;
  37. }
  38. EXPORT_SYMBOL(atari_microwire_cmd);
  39. /* PSG base frequency */
  40. #define PSG_FREQ 125000
  41. /* PSG envelope base frequency times 10 */
  42. #define PSG_ENV_FREQ_10 78125
  43. void atari_mksound (unsigned int hz, unsigned int ticks)
  44. {
  45. /* Generates sound of some frequency for some number of clock
  46. ticks. */
  47. unsigned long flags;
  48. unsigned char tmp;
  49. int period;
  50. local_irq_save(flags);
  51. /* Disable generator A in mixer control. */
  52. sound_ym.rd_data_reg_sel = 7;
  53. tmp = sound_ym.rd_data_reg_sel;
  54. tmp |= 011;
  55. sound_ym.wd_data = tmp;
  56. if (hz) {
  57. /* Convert from frequency value to PSG period value (base
  58. frequency 125 kHz). */
  59. period = PSG_FREQ / hz;
  60. if (period > 0xfff) period = 0xfff;
  61. /* Set generator A frequency to hz. */
  62. sound_ym.rd_data_reg_sel = 0;
  63. sound_ym.wd_data = period & 0xff;
  64. sound_ym.rd_data_reg_sel = 1;
  65. sound_ym.wd_data = (period >> 8) & 0xf;
  66. if (ticks) {
  67. /* Set length of envelope (max 8 sec). */
  68. int length = (ticks * PSG_ENV_FREQ_10) / HZ / 10;
  69. if (length > 0xffff) length = 0xffff;
  70. sound_ym.rd_data_reg_sel = 11;
  71. sound_ym.wd_data = length & 0xff;
  72. sound_ym.rd_data_reg_sel = 12;
  73. sound_ym.wd_data = length >> 8;
  74. /* Envelope form: max -> min single. */
  75. sound_ym.rd_data_reg_sel = 13;
  76. sound_ym.wd_data = 0;
  77. /* Use envelope for generator A. */
  78. sound_ym.rd_data_reg_sel = 8;
  79. sound_ym.wd_data = 0x10;
  80. } else {
  81. /* Set generator A level to maximum, no envelope. */
  82. sound_ym.rd_data_reg_sel = 8;
  83. sound_ym.wd_data = 15;
  84. }
  85. /* Turn on generator A in mixer control. */
  86. sound_ym.rd_data_reg_sel = 7;
  87. tmp &= ~1;
  88. sound_ym.wd_data = tmp;
  89. }
  90. local_irq_restore(flags);
  91. }