Takashi Sakamoto | 6c3cef4 | 2017-03-22 21:30:11 +0900 | [diff] [blame] | 1 | /* |
| 2 | * motu.h - a part of driver for MOTU FireWire series |
| 3 | * |
| 4 | * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp> |
| 5 | * |
| 6 | * Licensed under the terms of the GNU General Public License, version 2. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SOUND_FIREWIRE_MOTU_H_INCLUDED |
| 10 | #define SOUND_FIREWIRE_MOTU_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 | |
| 20 | #include <sound/control.h> |
| 21 | #include <sound/core.h> |
Takashi Sakamoto | 4641c93 | 2017-03-22 21:30:18 +0900 | [diff] [blame] | 22 | #include <sound/pcm.h> |
Takashi Sakamoto | 4638ec6e | 2017-03-22 21:30:21 +0900 | [diff] [blame^] | 23 | #include <sound/info.h> |
Takashi Sakamoto | 6c3cef4 | 2017-03-22 21:30:11 +0900 | [diff] [blame] | 24 | |
Takashi Sakamoto | 8865a31 | 2017-03-22 21:30:12 +0900 | [diff] [blame] | 25 | #include "../lib.h" |
Takashi Sakamoto | 4641c93 | 2017-03-22 21:30:18 +0900 | [diff] [blame] | 26 | #include "../amdtp-stream.h" |
Takashi Sakamoto | 9b2bb4f | 2017-03-22 21:30:20 +0900 | [diff] [blame] | 27 | #include "../iso-resources.h" |
Takashi Sakamoto | 8865a31 | 2017-03-22 21:30:12 +0900 | [diff] [blame] | 28 | |
Takashi Sakamoto | 59f6482 | 2017-03-22 21:30:14 +0900 | [diff] [blame] | 29 | struct snd_motu_packet_format { |
Takashi Sakamoto | 59f6482 | 2017-03-22 21:30:14 +0900 | [diff] [blame] | 30 | unsigned char pcm_byte_offset; |
| 31 | |
| 32 | unsigned char msg_chunks; |
| 33 | unsigned char fixed_part_pcm_chunks[3]; |
| 34 | unsigned char differed_part_pcm_chunks[3]; |
| 35 | }; |
| 36 | |
Takashi Sakamoto | 6c3cef4 | 2017-03-22 21:30:11 +0900 | [diff] [blame] | 37 | struct snd_motu { |
| 38 | struct snd_card *card; |
| 39 | struct fw_unit *unit; |
| 40 | struct mutex mutex; |
Takashi Sakamoto | 8865a31 | 2017-03-22 21:30:12 +0900 | [diff] [blame] | 41 | |
| 42 | bool registered; |
| 43 | struct delayed_work dwork; |
Takashi Sakamoto | 5e03c33 | 2017-03-22 21:30:13 +0900 | [diff] [blame] | 44 | |
| 45 | /* Model dependent information. */ |
| 46 | const struct snd_motu_spec *spec; |
Takashi Sakamoto | 59f6482 | 2017-03-22 21:30:14 +0900 | [diff] [blame] | 47 | |
| 48 | /* For packet streaming */ |
| 49 | struct snd_motu_packet_format tx_packet_formats; |
| 50 | struct snd_motu_packet_format rx_packet_formats; |
Takashi Sakamoto | 4641c93 | 2017-03-22 21:30:18 +0900 | [diff] [blame] | 51 | struct amdtp_stream tx_stream; |
| 52 | struct amdtp_stream rx_stream; |
Takashi Sakamoto | 9b2bb4f | 2017-03-22 21:30:20 +0900 | [diff] [blame] | 53 | struct fw_iso_resources tx_resources; |
| 54 | struct fw_iso_resources rx_resources; |
| 55 | unsigned int capture_substreams; |
| 56 | unsigned int playback_substreams; |
Takashi Sakamoto | 2e76701 | 2017-03-22 21:30:19 +0900 | [diff] [blame] | 57 | |
| 58 | /* For notification. */ |
| 59 | struct fw_address_handler async_handler; |
| 60 | u32 msg; |
Takashi Sakamoto | 5e03c33 | 2017-03-22 21:30:13 +0900 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | enum snd_motu_spec_flags { |
| 64 | SND_MOTU_SPEC_SUPPORT_CLOCK_X2 = 0x0001, |
| 65 | SND_MOTU_SPEC_SUPPORT_CLOCK_X4 = 0x0002, |
| 66 | SND_MOTU_SPEC_TX_MICINST_CHUNK = 0x0004, |
| 67 | SND_MOTU_SPEC_TX_RETURN_CHUNK = 0x0008, |
| 68 | SND_MOTU_SPEC_TX_REVERB_CHUNK = 0x0010, |
| 69 | SND_MOTU_SPEC_TX_AESEBU_CHUNK = 0x0020, |
| 70 | SND_MOTU_SPEC_HAS_OPT_IFACE_A = 0x0040, |
| 71 | SND_MOTU_SPEC_HAS_OPT_IFACE_B = 0x0080, |
| 72 | SND_MOTU_SPEC_HAS_MIDI = 0x0100, |
| 73 | }; |
| 74 | |
Takashi Sakamoto | 59f6482 | 2017-03-22 21:30:14 +0900 | [diff] [blame] | 75 | #define SND_MOTU_CLOCK_RATE_COUNT 6 |
| 76 | extern const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT]; |
| 77 | |
| 78 | enum snd_motu_clock_source { |
| 79 | SND_MOTU_CLOCK_SOURCE_INTERNAL, |
| 80 | SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB, |
| 81 | SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT, |
| 82 | SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A, |
| 83 | SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B, |
| 84 | SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT, |
| 85 | SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A, |
| 86 | SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B, |
| 87 | SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX, |
| 88 | SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR, |
| 89 | SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC, |
| 90 | SND_MOTU_CLOCK_SOURCE_UNKNOWN, |
| 91 | }; |
| 92 | |
| 93 | struct snd_motu_protocol { |
| 94 | int (*get_clock_rate)(struct snd_motu *motu, unsigned int *rate); |
| 95 | int (*set_clock_rate)(struct snd_motu *motu, unsigned int rate); |
| 96 | int (*get_clock_source)(struct snd_motu *motu, |
| 97 | enum snd_motu_clock_source *source); |
| 98 | int (*switch_fetching_mode)(struct snd_motu *motu, bool enable); |
| 99 | int (*cache_packet_formats)(struct snd_motu *motu); |
| 100 | }; |
| 101 | |
Takashi Sakamoto | 5e03c33 | 2017-03-22 21:30:13 +0900 | [diff] [blame] | 102 | struct snd_motu_spec { |
| 103 | const char *const name; |
| 104 | enum snd_motu_spec_flags flags; |
| 105 | |
| 106 | unsigned char analog_in_ports; |
| 107 | unsigned char analog_out_ports; |
Takashi Sakamoto | 59f6482 | 2017-03-22 21:30:14 +0900 | [diff] [blame] | 108 | |
| 109 | const struct snd_motu_protocol *const protocol; |
Takashi Sakamoto | 6c3cef4 | 2017-03-22 21:30:11 +0900 | [diff] [blame] | 110 | }; |
| 111 | |
Takashi Sakamoto | 4641c93 | 2017-03-22 21:30:18 +0900 | [diff] [blame] | 112 | int amdtp_motu_init(struct amdtp_stream *s, struct fw_unit *unit, |
| 113 | enum amdtp_stream_direction dir, |
| 114 | const struct snd_motu_protocol *const protocol); |
| 115 | int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate, |
| 116 | struct snd_motu_packet_format *formats); |
| 117 | int amdtp_motu_add_pcm_hw_constraints(struct amdtp_stream *s, |
| 118 | struct snd_pcm_runtime *runtime); |
Takashi Sakamoto | 2e76701 | 2017-03-22 21:30:19 +0900 | [diff] [blame] | 119 | |
| 120 | int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg, |
| 121 | size_t size); |
| 122 | int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg, |
| 123 | size_t size); |
| 124 | int snd_motu_transaction_register(struct snd_motu *motu); |
| 125 | int snd_motu_transaction_reregister(struct snd_motu *motu); |
| 126 | void snd_motu_transaction_unregister(struct snd_motu *motu); |
Takashi Sakamoto | 9b2bb4f | 2017-03-22 21:30:20 +0900 | [diff] [blame] | 127 | |
| 128 | int snd_motu_stream_init_duplex(struct snd_motu *motu); |
| 129 | void snd_motu_stream_destroy_duplex(struct snd_motu *motu); |
| 130 | int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate); |
| 131 | void snd_motu_stream_stop_duplex(struct snd_motu *motu); |
Takashi Sakamoto | 4638ec6e | 2017-03-22 21:30:21 +0900 | [diff] [blame^] | 132 | |
| 133 | void snd_motu_proc_init(struct snd_motu *motu); |
Takashi Sakamoto | 6c3cef4 | 2017-03-22 21:30:11 +0900 | [diff] [blame] | 134 | #endif |