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