atasound.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/pgtable.h>
  27. #include <asm/atariints.h>
  28. /*
  29. * stuff from the old atasound.c
  30. */
  31. void atari_microwire_cmd (int cmd)
  32. {
  33. tt_microwire.mask = 0x7ff;
  34. tt_microwire.data = MW_LM1992_ADDR | cmd;
  35. /* Busy wait for data being completely sent :-( */
  36. while( tt_microwire.mask != 0x7ff)
  37. ;
  38. }
  39. EXPORT_SYMBOL(atari_microwire_cmd);
  40. /* PSG base frequency */
  41. #define PSG_FREQ 125000
  42. /* PSG envelope base frequency times 10 */
  43. #define PSG_ENV_FREQ_10 78125
  44. void atari_mksound (unsigned int hz, unsigned int ticks)
  45. {
  46. /* Generates sound of some frequency for some number of clock
  47. ticks. */
  48. unsigned long flags;
  49. unsigned char tmp;
  50. int period;
  51. local_irq_save(flags);
  52. /* Disable generator A in mixer control. */
  53. sound_ym.rd_data_reg_sel = 7;
  54. tmp = sound_ym.rd_data_reg_sel;
  55. tmp |= 011;
  56. sound_ym.wd_data = tmp;
  57. if (hz) {
  58. /* Convert from frequency value to PSG period value (base
  59. frequency 125 kHz). */
  60. period = PSG_FREQ / hz;
  61. if (period > 0xfff) period = 0xfff;
  62. /* Set generator A frequency to hz. */
  63. sound_ym.rd_data_reg_sel = 0;
  64. sound_ym.wd_data = period & 0xff;
  65. sound_ym.rd_data_reg_sel = 1;
  66. sound_ym.wd_data = (period >> 8) & 0xf;
  67. if (ticks) {
  68. /* Set length of envelope (max 8 sec). */
  69. int length = (ticks * PSG_ENV_FREQ_10) / HZ / 10;
  70. if (length > 0xffff) length = 0xffff;
  71. sound_ym.rd_data_reg_sel = 11;
  72. sound_ym.wd_data = length & 0xff;
  73. sound_ym.rd_data_reg_sel = 12;
  74. sound_ym.wd_data = length >> 8;
  75. /* Envelope form: max -> min single. */
  76. sound_ym.rd_data_reg_sel = 13;
  77. sound_ym.wd_data = 0;
  78. /* Use envelope for generator A. */
  79. sound_ym.rd_data_reg_sel = 8;
  80. sound_ym.wd_data = 0x10;
  81. } else {
  82. /* Set generator A level to maximum, no envelope. */
  83. sound_ym.rd_data_reg_sel = 8;
  84. sound_ym.wd_data = 15;
  85. }
  86. /* Turn on generator A in mixer control. */
  87. sound_ym.rd_data_reg_sel = 7;
  88. tmp &= ~1;
  89. sound_ym.wd_data = tmp;
  90. }
  91. local_irq_restore(flags);
  92. }