Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 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 | |
| 9 | #ifndef SOUND_FIREFACE_H_INCLUDED |
| 10 | #define SOUND_FIREFACE_H_INCLUDED |
| 11 | |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/firewire.h> |
| 14 | #include <linux/firewire-constants.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/mod_devicetable.h> |
| 17 | #include <linux/mutex.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/compat.h> |
Takashi Sakamoto | f656edd | 2017-03-31 22:06:11 +0900 | [diff] [blame] | 20 | #include <linux/sched/signal.h> |
Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 21 | |
| 22 | #include <sound/core.h> |
Takashi Sakamoto | 53eb086 | 2017-03-31 22:06:02 +0900 | [diff] [blame] | 23 | #include <sound/info.h> |
Takashi Sakamoto | 1917429 | 2017-03-31 22:06:03 +0900 | [diff] [blame] | 24 | #include <sound/rawmidi.h> |
Takashi Sakamoto | 4b31643 | 2017-03-31 22:06:10 +0900 | [diff] [blame] | 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
Takashi Sakamoto | f656edd | 2017-03-31 22:06:11 +0900 | [diff] [blame] | 27 | #include <sound/hwdep.h> |
| 28 | #include <sound/firewire.h> |
Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 29 | |
Takashi Sakamoto | 324540c | 2017-03-31 22:06:00 +0900 | [diff] [blame] | 30 | #include "../lib.h" |
Takashi Sakamoto | 6fb7db9 | 2017-03-31 22:06:08 +0900 | [diff] [blame] | 31 | #include "../amdtp-stream.h" |
Takashi Sakamoto | 75d6d89 | 2017-03-31 22:06:09 +0900 | [diff] [blame] | 32 | #include "../iso-resources.h" |
Takashi Sakamoto | 324540c | 2017-03-31 22:06:00 +0900 | [diff] [blame] | 33 | |
Takashi Sakamoto | ed90f91 | 2017-03-31 22:06:01 +0900 | [diff] [blame] | 34 | #define SND_FF_STREAM_MODES 3 |
| 35 | |
Takashi Sakamoto | 1917429 | 2017-03-31 22:06:03 +0900 | [diff] [blame] | 36 | #define SND_FF_MAXIMIM_MIDI_QUADS 9 |
| 37 | #define SND_FF_IN_MIDI_PORTS 2 |
| 38 | #define SND_FF_OUT_MIDI_PORTS 2 |
| 39 | |
Takashi Sakamoto | 53eb086 | 2017-03-31 22:06:02 +0900 | [diff] [blame] | 40 | struct snd_ff_protocol; |
Takashi Sakamoto | ed90f91 | 2017-03-31 22:06:01 +0900 | [diff] [blame] | 41 | struct snd_ff_spec { |
| 42 | const char *const name; |
| 43 | |
| 44 | const unsigned int pcm_capture_channels[SND_FF_STREAM_MODES]; |
| 45 | const unsigned int pcm_playback_channels[SND_FF_STREAM_MODES]; |
| 46 | |
| 47 | unsigned int midi_in_ports; |
| 48 | unsigned int midi_out_ports; |
Takashi Sakamoto | 53eb086 | 2017-03-31 22:06:02 +0900 | [diff] [blame] | 49 | |
Takashi Sakamoto | 782fbec | 2017-08-22 22:58:15 +0900 | [diff] [blame] | 50 | const struct snd_ff_protocol *protocol; |
Takashi Sakamoto | ed90f91 | 2017-03-31 22:06:01 +0900 | [diff] [blame] | 51 | }; |
| 52 | |
Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 53 | struct snd_ff { |
| 54 | struct snd_card *card; |
| 55 | struct fw_unit *unit; |
| 56 | struct mutex mutex; |
Takashi Sakamoto | ff2c293 | 2017-03-31 22:06:04 +0900 | [diff] [blame] | 57 | spinlock_t lock; |
Takashi Sakamoto | 324540c | 2017-03-31 22:06:00 +0900 | [diff] [blame] | 58 | |
| 59 | bool registered; |
| 60 | struct delayed_work dwork; |
Takashi Sakamoto | ed90f91 | 2017-03-31 22:06:01 +0900 | [diff] [blame] | 61 | |
| 62 | const struct snd_ff_spec *spec; |
Takashi Sakamoto | 1917429 | 2017-03-31 22:06:03 +0900 | [diff] [blame] | 63 | |
| 64 | /* To handle MIDI tx. */ |
| 65 | struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS]; |
| 66 | struct fw_address_handler async_handler; |
| 67 | |
| 68 | /* TO handle MIDI rx. */ |
| 69 | struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS]; |
| 70 | u8 running_status[SND_FF_OUT_MIDI_PORTS]; |
| 71 | __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS]; |
| 72 | struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS]; |
| 73 | struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS]; |
| 74 | ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS]; |
| 75 | bool rx_midi_error[SND_FF_OUT_MIDI_PORTS]; |
| 76 | unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS]; |
Takashi Sakamoto | 75d6d89 | 2017-03-31 22:06:09 +0900 | [diff] [blame] | 77 | |
| 78 | unsigned int substreams_counter; |
| 79 | struct amdtp_stream tx_stream; |
| 80 | struct amdtp_stream rx_stream; |
| 81 | struct fw_iso_resources tx_resources; |
| 82 | struct fw_iso_resources rx_resources; |
Takashi Sakamoto | f656edd | 2017-03-31 22:06:11 +0900 | [diff] [blame] | 83 | |
| 84 | int dev_lock_count; |
| 85 | bool dev_lock_changed; |
| 86 | wait_queue_head_t hwdep_wait; |
Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 87 | }; |
Takashi Sakamoto | 53eb086 | 2017-03-31 22:06:02 +0900 | [diff] [blame] | 88 | |
| 89 | enum snd_ff_clock_src { |
| 90 | SND_FF_CLOCK_SRC_INTERNAL, |
| 91 | SND_FF_CLOCK_SRC_SPDIF, |
| 92 | SND_FF_CLOCK_SRC_ADAT, |
| 93 | SND_FF_CLOCK_SRC_WORD, |
| 94 | SND_FF_CLOCK_SRC_LTC, |
| 95 | /* TODO: perhaps ADAT2 and TCO exists. */ |
| 96 | }; |
| 97 | |
| 98 | struct snd_ff_protocol { |
| 99 | int (*get_clock)(struct snd_ff *ff, unsigned int *rate, |
| 100 | enum snd_ff_clock_src *src); |
| 101 | int (*begin_session)(struct snd_ff *ff, unsigned int rate); |
| 102 | void (*finish_session)(struct snd_ff *ff); |
| 103 | int (*switch_fetching_mode)(struct snd_ff *ff, bool enable); |
| 104 | |
| 105 | void (*dump_sync_status)(struct snd_ff *ff, |
| 106 | struct snd_info_buffer *buffer); |
| 107 | void (*dump_clock_config)(struct snd_ff *ff, |
| 108 | struct snd_info_buffer *buffer); |
| 109 | |
| 110 | u64 midi_high_addr_reg; |
| 111 | u64 midi_rx_port_0_reg; |
| 112 | u64 midi_rx_port_1_reg; |
| 113 | }; |
| 114 | |
Takashi Sakamoto | 782fbec | 2017-08-22 22:58:15 +0900 | [diff] [blame] | 115 | extern const struct snd_ff_protocol snd_ff_protocol_ff400; |
Takashi Sakamoto | 76fdb3a9 | 2017-03-31 22:06:12 +0900 | [diff] [blame] | 116 | |
Takashi Sakamoto | 1917429 | 2017-03-31 22:06:03 +0900 | [diff] [blame] | 117 | int snd_ff_transaction_register(struct snd_ff *ff); |
| 118 | int snd_ff_transaction_reregister(struct snd_ff *ff); |
| 119 | void snd_ff_transaction_unregister(struct snd_ff *ff); |
| 120 | |
Takashi Sakamoto | 6fb7db9 | 2017-03-31 22:06:08 +0900 | [diff] [blame] | 121 | int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate, |
| 122 | unsigned int pcm_channels); |
| 123 | int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s, |
| 124 | struct snd_pcm_runtime *runtime); |
| 125 | int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit, |
| 126 | enum amdtp_stream_direction dir); |
| 127 | |
Takashi Sakamoto | 75d6d89 | 2017-03-31 22:06:09 +0900 | [diff] [blame] | 128 | int snd_ff_stream_init_duplex(struct snd_ff *ff); |
| 129 | void snd_ff_stream_destroy_duplex(struct snd_ff *ff); |
| 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 | |
Takashi Sakamoto | f656edd | 2017-03-31 22:06:11 +0900 | [diff] [blame] | 134 | void snd_ff_stream_lock_changed(struct snd_ff *ff); |
| 135 | int snd_ff_stream_lock_try(struct snd_ff *ff); |
| 136 | void snd_ff_stream_lock_release(struct snd_ff *ff); |
| 137 | |
Takashi Sakamoto | d3fc7aa | 2017-03-31 22:06:05 +0900 | [diff] [blame] | 138 | void snd_ff_proc_init(struct snd_ff *ff); |
| 139 | |
Takashi Sakamoto | ff2c293 | 2017-03-31 22:06:04 +0900 | [diff] [blame] | 140 | int snd_ff_create_midi_devices(struct snd_ff *ff); |
| 141 | |
Takashi Sakamoto | 4b31643 | 2017-03-31 22:06:10 +0900 | [diff] [blame] | 142 | int snd_ff_create_pcm_devices(struct snd_ff *ff); |
| 143 | |
Takashi Sakamoto | f656edd | 2017-03-31 22:06:11 +0900 | [diff] [blame] | 144 | int snd_ff_create_hwdep_devices(struct snd_ff *ff); |
| 145 | |
Takashi Sakamoto | 17c4e5e | 2017-03-31 22:05:59 +0900 | [diff] [blame] | 146 | #endif |