ff.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ff.h - a part of driver for RME Fireface series
  4. *
  5. * Copyright (c) 2015-2017 Takashi Sakamoto
  6. */
  7. #ifndef SOUND_FIREFACE_H_INCLUDED
  8. #define SOUND_FIREFACE_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/info.h>
  20. #include <sound/rawmidi.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/hwdep.h>
  24. #include <sound/firewire.h>
  25. #include "../lib.h"
  26. #include "../amdtp-stream.h"
  27. #include "../iso-resources.h"
  28. #define SND_FF_MAXIMIM_MIDI_QUADS 9
  29. #define SND_FF_IN_MIDI_PORTS 2
  30. #define SND_FF_OUT_MIDI_PORTS 2
  31. enum snd_ff_unit_version {
  32. SND_FF_UNIT_VERSION_FF800 = 0x000001,
  33. SND_FF_UNIT_VERSION_FF400 = 0x000002,
  34. SND_FF_UNIT_VERSION_UFX = 0x000003,
  35. SND_FF_UNIT_VERSION_UCX = 0x000004,
  36. SND_FF_UNIT_VERSION_802 = 0x000005,
  37. };
  38. enum snd_ff_stream_mode {
  39. SND_FF_STREAM_MODE_LOW = 0,
  40. SND_FF_STREAM_MODE_MID,
  41. SND_FF_STREAM_MODE_HIGH,
  42. SND_FF_STREAM_MODE_COUNT,
  43. };
  44. struct snd_ff_protocol;
  45. struct snd_ff_spec {
  46. const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
  47. const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
  48. unsigned int midi_in_ports;
  49. unsigned int midi_out_ports;
  50. const struct snd_ff_protocol *protocol;
  51. u64 midi_high_addr;
  52. u8 midi_addr_range;
  53. u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
  54. };
  55. struct snd_ff {
  56. struct snd_card *card;
  57. struct fw_unit *unit;
  58. struct mutex mutex;
  59. spinlock_t lock;
  60. enum snd_ff_unit_version unit_version;
  61. const struct snd_ff_spec *spec;
  62. /* To handle MIDI tx. */
  63. struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
  64. struct fw_address_handler async_handler;
  65. /* TO handle MIDI rx. */
  66. struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
  67. bool on_sysex[SND_FF_OUT_MIDI_PORTS];
  68. __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
  69. struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
  70. struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
  71. ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
  72. bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
  73. unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
  74. unsigned int substreams_counter;
  75. struct amdtp_stream tx_stream;
  76. struct amdtp_stream rx_stream;
  77. struct fw_iso_resources tx_resources;
  78. struct fw_iso_resources rx_resources;
  79. int dev_lock_count;
  80. bool dev_lock_changed;
  81. wait_queue_head_t hwdep_wait;
  82. struct amdtp_domain domain;
  83. void *msg_parser;
  84. };
  85. enum snd_ff_clock_src {
  86. SND_FF_CLOCK_SRC_INTERNAL,
  87. SND_FF_CLOCK_SRC_SPDIF,
  88. SND_FF_CLOCK_SRC_ADAT1,
  89. SND_FF_CLOCK_SRC_ADAT2,
  90. SND_FF_CLOCK_SRC_WORD,
  91. SND_FF_CLOCK_SRC_LTC,
  92. /* TODO: perhaps TCO exists. */
  93. };
  94. struct snd_ff_protocol {
  95. size_t msg_parser_size;
  96. bool (*has_msg)(struct snd_ff *ff);
  97. long (*copy_msg_to_user)(struct snd_ff *ff, char __user *buf, long count);
  98. void (*handle_msg)(struct snd_ff *ff, unsigned int offset, const __le32 *buf,
  99. size_t length, u32 tstamp);
  100. int (*fill_midi_msg)(struct snd_ff *ff,
  101. struct snd_rawmidi_substream *substream,
  102. unsigned int port);
  103. int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
  104. enum snd_ff_clock_src *src);
  105. int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
  106. int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
  107. int (*begin_session)(struct snd_ff *ff, unsigned int rate);
  108. void (*finish_session)(struct snd_ff *ff);
  109. void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
  110. };
  111. extern const struct snd_ff_protocol snd_ff_protocol_ff800;
  112. extern const struct snd_ff_protocol snd_ff_protocol_ff400;
  113. extern const struct snd_ff_protocol snd_ff_protocol_latter;
  114. int snd_ff_transaction_register(struct snd_ff *ff);
  115. int snd_ff_transaction_reregister(struct snd_ff *ff);
  116. void snd_ff_transaction_unregister(struct snd_ff *ff);
  117. int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
  118. unsigned int pcm_channels);
  119. int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
  120. struct snd_pcm_runtime *runtime);
  121. int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
  122. enum amdtp_stream_direction dir);
  123. int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
  124. enum snd_ff_stream_mode *mode);
  125. int snd_ff_stream_init_duplex(struct snd_ff *ff);
  126. void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
  127. int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
  128. unsigned int frames_per_period,
  129. unsigned int frames_per_buffer);
  130. int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
  131. void snd_ff_stream_stop_duplex(struct snd_ff *ff);
  132. void snd_ff_stream_update_duplex(struct snd_ff *ff);
  133. void snd_ff_stream_lock_changed(struct snd_ff *ff);
  134. int snd_ff_stream_lock_try(struct snd_ff *ff);
  135. void snd_ff_stream_lock_release(struct snd_ff *ff);
  136. void snd_ff_proc_init(struct snd_ff *ff);
  137. const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
  138. int snd_ff_create_midi_devices(struct snd_ff *ff);
  139. int snd_ff_create_pcm_devices(struct snd_ff *ff);
  140. int snd_ff_create_hwdep_devices(struct snd_ff *ff);
  141. #endif