tascam.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 <linux/sched/signal.h>
  19. #include <sound/core.h>
  20. #include <sound/initval.h>
  21. #include <sound/info.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/firewire.h>
  25. #include <sound/hwdep.h>
  26. #include <sound/rawmidi.h>
  27. #include "../lib.h"
  28. #include "../amdtp-stream.h"
  29. #include "../iso-resources.h"
  30. struct snd_tscm_spec {
  31. const char *const name;
  32. bool has_adat;
  33. bool has_spdif;
  34. unsigned int pcm_capture_analog_channels;
  35. unsigned int pcm_playback_analog_channels;
  36. unsigned int midi_capture_ports;
  37. unsigned int midi_playback_ports;
  38. };
  39. #define TSCM_MIDI_IN_PORT_MAX 4
  40. #define TSCM_MIDI_OUT_PORT_MAX 4
  41. struct snd_fw_async_midi_port {
  42. struct fw_device *parent;
  43. struct work_struct work;
  44. bool idling;
  45. ktime_t next_ktime;
  46. bool error;
  47. struct fw_transaction transaction;
  48. u8 buf[4];
  49. u8 running_status;
  50. bool on_sysex;
  51. struct snd_rawmidi_substream *substream;
  52. int consume_bytes;
  53. };
  54. struct snd_tscm {
  55. struct snd_card *card;
  56. struct fw_unit *unit;
  57. struct mutex mutex;
  58. spinlock_t lock;
  59. bool registered;
  60. struct delayed_work dwork;
  61. const struct snd_tscm_spec *spec;
  62. struct fw_iso_resources tx_resources;
  63. struct fw_iso_resources rx_resources;
  64. struct amdtp_stream tx_stream;
  65. struct amdtp_stream rx_stream;
  66. unsigned int substreams_counter;
  67. int dev_lock_count;
  68. bool dev_lock_changed;
  69. wait_queue_head_t hwdep_wait;
  70. /* For MIDI message incoming transactions. */
  71. struct fw_address_handler async_handler;
  72. struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
  73. /* For MIDI message outgoing transactions. */
  74. struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
  75. };
  76. #define TSCM_ADDR_BASE 0xffff00000000ull
  77. #define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
  78. #define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
  79. #define TSCM_OFFSET_FIRMWARE_ARM 0x0008
  80. #define TSCM_OFFSET_FIRMWARE_HW 0x000c
  81. #define TSCM_OFFSET_ISOC_TX_CH 0x0200
  82. #define TSCM_OFFSET_UNKNOWN 0x0204
  83. #define TSCM_OFFSET_START_STREAMING 0x0208
  84. #define TSCM_OFFSET_ISOC_RX_CH 0x020c
  85. #define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
  86. #define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
  87. #define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
  88. #define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
  89. #define TSCM_OFFSET_ISOC_TX_ON 0x0220
  90. /* Unknown 0x0224 */
  91. #define TSCM_OFFSET_CLOCK_STATUS 0x0228
  92. #define TSCM_OFFSET_SET_OPTION 0x022c
  93. #define TSCM_OFFSET_MIDI_TX_ON 0x0300
  94. #define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
  95. #define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
  96. #define TSCM_OFFSET_LED_POWER 0x0404
  97. #define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
  98. enum snd_tscm_clock {
  99. SND_TSCM_CLOCK_INTERNAL = 0,
  100. SND_TSCM_CLOCK_WORD = 1,
  101. SND_TSCM_CLOCK_SPDIF = 2,
  102. SND_TSCM_CLOCK_ADAT = 3,
  103. };
  104. int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
  105. enum amdtp_stream_direction dir, unsigned int pcm_channels);
  106. int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
  107. int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
  108. struct snd_pcm_runtime *runtime);
  109. int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
  110. int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
  111. enum snd_tscm_clock *clock);
  112. int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
  113. void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
  114. void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
  115. int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
  116. void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
  117. void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
  118. int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
  119. void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
  120. void snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port);
  121. static inline void
  122. snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
  123. struct snd_rawmidi_substream *substream)
  124. {
  125. if (!port->error) {
  126. port->substream = substream;
  127. schedule_work(&port->work);
  128. }
  129. }
  130. static inline void
  131. snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
  132. {
  133. port->substream = NULL;
  134. cancel_work_sync(&port->work);
  135. port->error = false;
  136. }
  137. int snd_tscm_transaction_register(struct snd_tscm *tscm);
  138. int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
  139. void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
  140. void snd_tscm_proc_init(struct snd_tscm *tscm);
  141. int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
  142. int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
  143. int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
  144. #endif