au88x0_mpu401.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/time.h>
  24. #include <linux/init.h>
  25. #include <sound/core.h>
  26. #include <sound/mpu401.h>
  27. #include "au88x0.h"
  28. /* Check for mpu401 mmio support. */
  29. /* MPU401 legacy support is only provided as a emergency fallback *
  30. * for older versions of ALSA. Its usage is strongly discouraged. */
  31. #ifndef MPU401_HW_AUREAL
  32. #define VORTEX_MPU401_LEGACY
  33. #endif
  34. /* Vortex MPU401 defines. */
  35. #define MIDI_CLOCK_DIV 0x61
  36. /* Standart MPU401 defines. */
  37. #define MPU401_RESET 0xff
  38. #define MPU401_ENTER_UART 0x3f
  39. #define MPU401_ACK 0xfe
  40. static int snd_vortex_midi(vortex_t *vortex)
  41. {
  42. struct snd_rawmidi *rmidi;
  43. int temp, mode;
  44. struct snd_mpu401 *mpu;
  45. unsigned long port;
  46. #ifdef VORTEX_MPU401_LEGACY
  47. /* EnableHardCodedMPU401Port() */
  48. /* Enable Legacy MIDI Interface port. */
  49. port = (0x03 << 5); /* FIXME: static address. 0x330 */
  50. temp =
  51. (hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) |
  52. CTRL_MIDI_EN | port;
  53. hwwrite(vortex->mmio, VORTEX_CTRL, temp);
  54. #else
  55. /* Disable Legacy MIDI Interface port. */
  56. temp =
  57. (hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) &
  58. ~CTRL_MIDI_EN;
  59. hwwrite(vortex->mmio, VORTEX_CTRL, temp);
  60. #endif
  61. /* Mpu401UartInit() */
  62. mode = 1;
  63. temp = hwread(vortex->mmio, VORTEX_CTRL2) & 0xffff00cf;
  64. temp |= (MIDI_CLOCK_DIV << 8) | ((mode >> 24) & 0xff) << 4;
  65. hwwrite(vortex->mmio, VORTEX_CTRL2, temp);
  66. hwwrite(vortex->mmio, VORTEX_MIDI_CMD, MPU401_RESET);
  67. /* Check if anything is OK. */
  68. temp = hwread(vortex->mmio, VORTEX_MIDI_DATA);
  69. if (temp != MPU401_ACK /*0xfe */ ) {
  70. dev_err(vortex->card->dev, "midi port doesn't acknowledge!\n");
  71. return -ENODEV;
  72. }
  73. /* Enable MPU401 interrupts. */
  74. hwwrite(vortex->mmio, VORTEX_IRQ_CTRL,
  75. hwread(vortex->mmio, VORTEX_IRQ_CTRL) | IRQ_MIDI);
  76. /* Create MPU401 instance. */
  77. #ifdef VORTEX_MPU401_LEGACY
  78. if ((temp =
  79. snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,
  80. MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
  81. hwwrite(vortex->mmio, VORTEX_CTRL,
  82. (hwread(vortex->mmio, VORTEX_CTRL) &
  83. ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
  84. return temp;
  85. }
  86. #else
  87. port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA);
  88. if ((temp =
  89. snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,
  90. MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO |
  91. MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
  92. hwwrite(vortex->mmio, VORTEX_CTRL,
  93. (hwread(vortex->mmio, VORTEX_CTRL) &
  94. ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
  95. return temp;
  96. }
  97. mpu = rmidi->private_data;
  98. mpu->cport = (unsigned long)(vortex->mmio + VORTEX_MIDI_CMD);
  99. #endif
  100. /* Overwrite MIDI name */
  101. snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI %d", CARD_NAME_SHORT , vortex->card->number);
  102. vortex->rmidi = rmidi;
  103. return 0;
  104. }