ff.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * ff.h - a part of driver for RME Fireface series
  3. *
  4. * Copyright (c) 2015-2017 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #ifndef SOUND_FIREFACE_H_INCLUDED
  9. #define SOUND_FIREFACE_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/info.h>
  21. #include <sound/rawmidi.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/hwdep.h>
  25. #include <sound/firewire.h>
  26. #include "../lib.h"
  27. #include "../amdtp-stream.h"
  28. #include "../iso-resources.h"
  29. #define SND_FF_STREAM_MODES 3
  30. #define SND_FF_MAXIMIM_MIDI_QUADS 9
  31. #define SND_FF_IN_MIDI_PORTS 2
  32. #define SND_FF_OUT_MIDI_PORTS 2
  33. struct snd_ff_protocol;
  34. struct snd_ff_spec {
  35. const char *const name;
  36. const unsigned int pcm_capture_channels[SND_FF_STREAM_MODES];
  37. const unsigned int pcm_playback_channels[SND_FF_STREAM_MODES];
  38. unsigned int midi_in_ports;
  39. unsigned int midi_out_ports;
  40. const struct snd_ff_protocol *protocol;
  41. };
  42. struct snd_ff {
  43. struct snd_card *card;
  44. struct fw_unit *unit;
  45. struct mutex mutex;
  46. spinlock_t lock;
  47. bool registered;
  48. struct delayed_work dwork;
  49. const struct snd_ff_spec *spec;
  50. /* To handle MIDI tx. */
  51. struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
  52. struct fw_address_handler async_handler;
  53. /* TO handle MIDI rx. */
  54. struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
  55. u8 running_status[SND_FF_OUT_MIDI_PORTS];
  56. __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
  57. struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
  58. struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
  59. ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
  60. bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
  61. unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
  62. unsigned int substreams_counter;
  63. struct amdtp_stream tx_stream;
  64. struct amdtp_stream rx_stream;
  65. struct fw_iso_resources tx_resources;
  66. struct fw_iso_resources rx_resources;
  67. int dev_lock_count;
  68. bool dev_lock_changed;
  69. wait_queue_head_t hwdep_wait;
  70. };
  71. enum snd_ff_clock_src {
  72. SND_FF_CLOCK_SRC_INTERNAL,
  73. SND_FF_CLOCK_SRC_SPDIF,
  74. SND_FF_CLOCK_SRC_ADAT,
  75. SND_FF_CLOCK_SRC_WORD,
  76. SND_FF_CLOCK_SRC_LTC,
  77. /* TODO: perhaps ADAT2 and TCO exists. */
  78. };
  79. struct snd_ff_protocol {
  80. int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
  81. enum snd_ff_clock_src *src);
  82. int (*begin_session)(struct snd_ff *ff, unsigned int rate);
  83. void (*finish_session)(struct snd_ff *ff);
  84. int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
  85. void (*dump_sync_status)(struct snd_ff *ff,
  86. struct snd_info_buffer *buffer);
  87. void (*dump_clock_config)(struct snd_ff *ff,
  88. struct snd_info_buffer *buffer);
  89. u64 midi_high_addr_reg;
  90. u64 midi_rx_port_0_reg;
  91. u64 midi_rx_port_1_reg;
  92. };
  93. extern const struct snd_ff_protocol snd_ff_protocol_ff400;
  94. int snd_ff_transaction_register(struct snd_ff *ff);
  95. int snd_ff_transaction_reregister(struct snd_ff *ff);
  96. void snd_ff_transaction_unregister(struct snd_ff *ff);
  97. int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
  98. unsigned int pcm_channels);
  99. int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
  100. struct snd_pcm_runtime *runtime);
  101. int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
  102. enum amdtp_stream_direction dir);
  103. int snd_ff_stream_init_duplex(struct snd_ff *ff);
  104. void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
  105. int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
  106. void snd_ff_stream_stop_duplex(struct snd_ff *ff);
  107. void snd_ff_stream_update_duplex(struct snd_ff *ff);
  108. void snd_ff_stream_lock_changed(struct snd_ff *ff);
  109. int snd_ff_stream_lock_try(struct snd_ff *ff);
  110. void snd_ff_stream_lock_release(struct snd_ff *ff);
  111. void snd_ff_proc_init(struct snd_ff *ff);
  112. int snd_ff_create_midi_devices(struct snd_ff *ff);
  113. int snd_ff_create_pcm_devices(struct snd_ff *ff);
  114. int snd_ff_create_hwdep_devices(struct snd_ff *ff);
  115. #endif