tascam.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * tascam.h - a part of driver for TASCAM FireWire series
  3. *
  4. * Copyright (c) 2015 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #ifndef SOUND_TASCAM_H_INCLUDED
  9. #define SOUND_TASCAM_H_INCLUDED
  10. #include <linux/device.h>
  11. #include <linux/firewire.h>
  12. #include <linux/firewire-constants.h>
  13. #include <linux/module.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/mutex.h>
  16. #include <linux/slab.h>
  17. #include <linux/compat.h>
  18. #include <sound/core.h>
  19. #include <sound/initval.h>
  20. #include <sound/info.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/firewire.h>
  24. #include <sound/hwdep.h>
  25. #include <sound/rawmidi.h>
  26. #include "../lib.h"
  27. #include "../amdtp-stream.h"
  28. #include "../iso-resources.h"
  29. struct snd_tscm_spec {
  30. const char *const name;
  31. bool has_adat;
  32. bool has_spdif;
  33. unsigned int pcm_capture_analog_channels;
  34. unsigned int pcm_playback_analog_channels;
  35. unsigned int midi_capture_ports;
  36. unsigned int midi_playback_ports;
  37. bool is_controller;
  38. };
  39. #define TSCM_MIDI_IN_PORT_MAX 4
  40. #define TSCM_MIDI_OUT_PORT_MAX 4
  41. struct snd_tscm {
  42. struct snd_card *card;
  43. struct fw_unit *unit;
  44. struct mutex mutex;
  45. spinlock_t lock;
  46. const struct snd_tscm_spec *spec;
  47. struct fw_iso_resources tx_resources;
  48. struct fw_iso_resources rx_resources;
  49. struct amdtp_stream tx_stream;
  50. struct amdtp_stream rx_stream;
  51. unsigned int substreams_counter;
  52. int dev_lock_count;
  53. bool dev_lock_changed;
  54. wait_queue_head_t hwdep_wait;
  55. /* For MIDI message incoming transactions. */
  56. struct fw_address_handler async_handler;
  57. struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
  58. /* For MIDI message outgoing transactions. */
  59. struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
  60. u8 running_status[TSCM_MIDI_OUT_PORT_MAX];
  61. bool on_sysex[TSCM_MIDI_OUT_PORT_MAX];
  62. /* For control messages. */
  63. struct snd_firewire_tascam_status *status;
  64. };
  65. #define TSCM_ADDR_BASE 0xffff00000000ull
  66. #define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
  67. #define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
  68. #define TSCM_OFFSET_FIRMWARE_ARM 0x0008
  69. #define TSCM_OFFSET_FIRMWARE_HW 0x000c
  70. #define TSCM_OFFSET_ISOC_TX_CH 0x0200
  71. #define TSCM_OFFSET_UNKNOWN 0x0204
  72. #define TSCM_OFFSET_START_STREAMING 0x0208
  73. #define TSCM_OFFSET_ISOC_RX_CH 0x020c
  74. #define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
  75. #define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
  76. #define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
  77. #define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
  78. #define TSCM_OFFSET_ISOC_TX_ON 0x0220
  79. /* Unknown 0x0224 */
  80. #define TSCM_OFFSET_CLOCK_STATUS 0x0228
  81. #define TSCM_OFFSET_SET_OPTION 0x022c
  82. #define TSCM_OFFSET_MIDI_TX_ON 0x0300
  83. #define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
  84. #define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
  85. #define TSCM_OFFSET_LED_POWER 0x0404
  86. #define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
  87. enum snd_tscm_clock {
  88. SND_TSCM_CLOCK_INTERNAL = 0,
  89. SND_TSCM_CLOCK_WORD = 1,
  90. SND_TSCM_CLOCK_SPDIF = 2,
  91. SND_TSCM_CLOCK_ADAT = 3,
  92. };
  93. int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
  94. enum amdtp_stream_direction dir, unsigned int pcm_channels);
  95. int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
  96. int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
  97. struct snd_pcm_runtime *runtime);
  98. void amdtp_tscm_set_pcm_format(struct amdtp_stream *s, snd_pcm_format_t format);
  99. int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
  100. int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
  101. enum snd_tscm_clock *clock);
  102. int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
  103. void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
  104. void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
  105. int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
  106. void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
  107. void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
  108. int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
  109. void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
  110. int snd_tscm_transaction_register(struct snd_tscm *tscm);
  111. int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
  112. void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
  113. void snd_tscm_proc_init(struct snd_tscm *tscm);
  114. int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
  115. int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
  116. int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
  117. #endif