tascam.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * tascam.h - a part of driver for TASCAM FireWire series
  4. *
  5. * Copyright (c) 2015 Takashi Sakamoto
  6. */
  7. #ifndef SOUND_TASCAM_H_INCLUDED
  8. #define SOUND_TASCAM_H_INCLUDED
  9. #include <linux/device.h>
  10. #include <linux/firewire.h>
  11. #include <linux/firewire-constants.h>
  12. #include <linux/module.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/mutex.h>
  15. #include <linux/slab.h>
  16. #include <linux/compat.h>
  17. #include <linux/sched/signal.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. };
  38. #define TSCM_MIDI_IN_PORT_MAX 4
  39. #define TSCM_MIDI_OUT_PORT_MAX 4
  40. struct snd_fw_async_midi_port {
  41. struct fw_device *parent;
  42. struct work_struct work;
  43. bool idling;
  44. ktime_t next_ktime;
  45. bool error;
  46. struct fw_transaction transaction;
  47. u8 buf[4];
  48. u8 running_status;
  49. bool on_sysex;
  50. struct snd_rawmidi_substream *substream;
  51. int consume_bytes;
  52. };
  53. #define SND_TSCM_QUEUE_COUNT 16
  54. struct snd_tscm {
  55. struct snd_card *card;
  56. struct fw_unit *unit;
  57. struct mutex mutex;
  58. spinlock_t lock;
  59. const struct snd_tscm_spec *spec;
  60. struct fw_iso_resources tx_resources;
  61. struct fw_iso_resources rx_resources;
  62. struct amdtp_stream tx_stream;
  63. struct amdtp_stream rx_stream;
  64. unsigned int substreams_counter;
  65. int dev_lock_count;
  66. bool dev_lock_changed;
  67. wait_queue_head_t hwdep_wait;
  68. /* For MIDI message incoming transactions. */
  69. struct fw_address_handler async_handler;
  70. struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
  71. /* For MIDI message outgoing transactions. */
  72. struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
  73. // A cache of status information in tx isoc packets.
  74. __be32 state[SNDRV_FIREWIRE_TASCAM_STATE_COUNT];
  75. struct snd_hwdep *hwdep;
  76. struct snd_firewire_tascam_change queue[SND_TSCM_QUEUE_COUNT];
  77. unsigned int pull_pos;
  78. unsigned int push_pos;
  79. struct amdtp_domain domain;
  80. bool need_long_tx_init_skip;
  81. };
  82. #define TSCM_ADDR_BASE 0xffff00000000ull
  83. #define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
  84. #define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
  85. #define TSCM_OFFSET_FIRMWARE_ARM 0x0008
  86. #define TSCM_OFFSET_FIRMWARE_HW 0x000c
  87. #define TSCM_OFFSET_ISOC_TX_CH 0x0200
  88. #define TSCM_OFFSET_UNKNOWN 0x0204
  89. #define TSCM_OFFSET_START_STREAMING 0x0208
  90. #define TSCM_OFFSET_ISOC_RX_CH 0x020c
  91. #define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
  92. #define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
  93. #define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
  94. #define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
  95. #define TSCM_OFFSET_ISOC_TX_ON 0x0220
  96. /* Unknown 0x0224 */
  97. #define TSCM_OFFSET_CLOCK_STATUS 0x0228
  98. #define TSCM_OFFSET_SET_OPTION 0x022c
  99. #define TSCM_OFFSET_MIDI_TX_ON 0x0300
  100. #define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
  101. #define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
  102. #define TSCM_OFFSET_LED_POWER 0x0404
  103. #define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
  104. // Although FE-8 supports the above registers, it has no I/O interfaces for
  105. // audio samples and music messages. Otherwise it supports another notification
  106. // for status and control message as well as LED brightening. The message
  107. // consists of quadlet-aligned data up to 32 quadlets. The first byte of message
  108. // is fixed to 0x40. The second byte is between 0x00 to 0x1f and represent each
  109. // control:
  110. // fader: 0x00-0x07
  111. // button: 0x0d, 0x0e
  112. // knob: 0x14-0x1b
  113. // sensing: 0x0b
  114. //
  115. // The rest two bytes represent state of the controls; e.g. current value for
  116. // fader and knob, bitmasks for button and sensing.
  117. // Just after turning on, 32 quadlets messages with 0x00-0x1f are immediately
  118. // sent in one transaction. After, several quadlets are sent in one transaction.
  119. //
  120. // TSCM_OFFSET_FE8_CTL_TX_ON 0x0310
  121. // TSCM_OFFSET_FE8_CTL_TX_ADDR_HI 0x0314
  122. // TSCM_OFFSET_FE8_CTL_TX_ADDR_LO 0x0318
  123. enum snd_tscm_clock {
  124. SND_TSCM_CLOCK_INTERNAL = 0,
  125. SND_TSCM_CLOCK_WORD = 1,
  126. SND_TSCM_CLOCK_SPDIF = 2,
  127. SND_TSCM_CLOCK_ADAT = 3,
  128. };
  129. int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
  130. enum amdtp_stream_direction dir, unsigned int pcm_channels);
  131. int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
  132. int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
  133. struct snd_pcm_runtime *runtime);
  134. int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
  135. int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
  136. enum snd_tscm_clock *clock);
  137. int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
  138. void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
  139. void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
  140. int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
  141. unsigned int frames_per_period,
  142. unsigned int frames_per_buffer);
  143. int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
  144. void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
  145. void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
  146. int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
  147. void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
  148. void snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port);
  149. static inline void
  150. snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
  151. struct snd_rawmidi_substream *substream)
  152. {
  153. if (!port->error) {
  154. port->substream = substream;
  155. schedule_work(&port->work);
  156. }
  157. }
  158. static inline void
  159. snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
  160. {
  161. port->substream = NULL;
  162. cancel_work_sync(&port->work);
  163. port->error = false;
  164. }
  165. int snd_tscm_transaction_register(struct snd_tscm *tscm);
  166. int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
  167. void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
  168. void snd_tscm_proc_init(struct snd_tscm *tscm);
  169. int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
  170. int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
  171. int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
  172. #endif