au88x0_mpu401.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * Routines for control of MPU-401 in UART mode
  4. *
  5. * Modified for the Aureal Vortex based Soundcards
  6. * by Manuel Jander (mjande@embedded.cl).
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <linux/time.h>
  25. #include <linux/init.h>
  26. #include <sound/core.h>
  27. #include <sound/mpu401.h>
  28. #include "au88x0.h"
  29. /* Check for mpu401 mmio support. */
  30. /* MPU401 legacy support is only provided as a emergency fallback *
  31. * for older versions of ALSA. Its usage is strongly discouraged. */
  32. #ifndef MPU401_HW_AUREAL
  33. #define VORTEX_MPU401_LEGACY
  34. #endif
  35. /* Vortex MPU401 defines. */
  36. #define MIDI_CLOCK_DIV 0x61
  37. /* Standart MPU401 defines. */
  38. #define MPU401_RESET 0xff
  39. #define MPU401_ENTER_UART 0x3f
  40. #define MPU401_ACK 0xfe
  41. static int __devinit snd_vortex_midi(vortex_t * vortex)
  42. {
  43. snd_rawmidi_t *rmidi;
  44. int temp, mode;
  45. mpu401_t *mpu;
  46. int port;
  47. #ifdef VORTEX_MPU401_LEGACY
  48. /* EnableHardCodedMPU401Port() */
  49. /* Enable Legacy MIDI Interface port. */
  50. port = (0x03 << 5); /* FIXME: static address. 0x330 */
  51. temp =
  52. (hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) |
  53. CTRL_MIDI_EN | port;
  54. hwwrite(vortex->mmio, VORTEX_CTRL, temp);
  55. #else
  56. /* Disable Legacy MIDI Interface port. */
  57. temp =
  58. (hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) &
  59. ~CTRL_MIDI_EN;
  60. hwwrite(vortex->mmio, VORTEX_CTRL, temp);
  61. #endif
  62. /* Mpu401UartInit() */
  63. mode = 1;
  64. temp = hwread(vortex->mmio, VORTEX_CTRL2) & 0xffff00cf;
  65. temp |= (MIDI_CLOCK_DIV << 8) | ((mode >> 24) & 0xff) << 4;
  66. hwwrite(vortex->mmio, VORTEX_CTRL2, temp);
  67. hwwrite(vortex->mmio, VORTEX_MIDI_CMD, MPU401_RESET);
  68. /* Set some kind of mode */
  69. if (mode)
  70. hwwrite(vortex->mmio, VORTEX_MIDI_CMD, MPU401_ENTER_UART);
  71. /* Check if anything is OK. */
  72. temp = hwread(vortex->mmio, VORTEX_MIDI_DATA);
  73. if (temp != MPU401_ACK /*0xfe */ ) {
  74. printk(KERN_ERR "midi port doesn't acknowledge!\n");
  75. return -ENODEV;
  76. }
  77. /* Enable MPU401 interrupts. */
  78. hwwrite(vortex->mmio, VORTEX_IRQ_CTRL,
  79. hwread(vortex->mmio, VORTEX_IRQ_CTRL) | IRQ_MIDI);
  80. /* Create MPU401 instance. */
  81. #ifdef VORTEX_MPU401_LEGACY
  82. if ((temp =
  83. snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,
  84. 0, 0, 0, &rmidi)) != 0) {
  85. hwwrite(vortex->mmio, VORTEX_CTRL,
  86. (hwread(vortex->mmio, VORTEX_CTRL) &
  87. ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
  88. return temp;
  89. }
  90. #else
  91. port = (unsigned long)(vortex->mmio + (VORTEX_MIDI_DATA >> 2));
  92. if ((temp =
  93. snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,
  94. 1, 0, 0, &rmidi)) != 0) {
  95. hwwrite(vortex->mmio, VORTEX_CTRL,
  96. (hwread(vortex->mmio, VORTEX_CTRL) &
  97. ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
  98. return temp;
  99. }
  100. mpu = rmidi->private_data;
  101. mpu->cport = (unsigned long)(vortex->mmio + (VORTEX_MIDI_CMD >> 2));
  102. #endif
  103. vortex->rmidi = rmidi;
  104. return 0;
  105. }