Takashi Sakamoto | b5b0433 | 2014-04-25 22:45:00 +0900 | [diff] [blame] | 1 | /* |
| 2 | * fireworks.h - a part of driver for Fireworks based devices |
| 3 | * |
| 4 | * Copyright (c) 2009-2010 Clemens Ladisch |
| 5 | * Copyright (c) 2013-2014 Takashi Sakamoto |
| 6 | * |
| 7 | * Licensed under the terms of the GNU General Public License, version 2. |
| 8 | */ |
| 9 | #ifndef SOUND_FIREWORKS_H_INCLUDED |
| 10 | #define SOUND_FIREWORKS_H_INCLUDED |
| 11 | |
| 12 | #include <linux/compat.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/firewire.h> |
| 15 | #include <linux/firewire-constants.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/mod_devicetable.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/slab.h> |
| 20 | |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/initval.h> |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 23 | #include <sound/pcm.h> |
Takashi Sakamoto | 6a22683 | 2014-04-25 22:45:08 +0900 | [diff] [blame] | 24 | #include <sound/info.h> |
Takashi Sakamoto | a63d3ff | 2014-04-25 22:45:09 +0900 | [diff] [blame] | 25 | #include <sound/rawmidi.h> |
Takashi Sakamoto | aa02bb6 | 2014-04-25 22:45:11 +0900 | [diff] [blame] | 26 | #include <sound/pcm_params.h> |
Takashi Sakamoto | 594ddce | 2014-04-25 22:45:12 +0900 | [diff] [blame^] | 27 | #include <sound/firewire.h> |
| 28 | #include <sound/hwdep.h> |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 29 | |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 30 | #include "../packets-buffer.h" |
| 31 | #include "../iso-resources.h" |
| 32 | #include "../amdtp.h" |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 33 | #include "../cmp.h" |
| 34 | #include "../lib.h" |
| 35 | |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 36 | #define SND_EFW_MAX_MIDI_OUT_PORTS 2 |
| 37 | #define SND_EFW_MAX_MIDI_IN_PORTS 2 |
| 38 | |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 39 | #define SND_EFW_MULTIPLIER_MODES 3 |
| 40 | #define HWINFO_NAME_SIZE_BYTES 32 |
| 41 | #define HWINFO_MAX_CAPS_GROUPS 8 |
| 42 | |
| 43 | /* |
| 44 | * This should be greater than maximum bytes for EFW response content. |
| 45 | * Currently response against command for isochronous channel mapping is |
| 46 | * confirmed to be the maximum one. But for flexibility, use maximum data |
| 47 | * payload for asynchronous primary packets at S100 (Cable base rate) in |
| 48 | * IEEE Std 1394-1995. |
| 49 | */ |
| 50 | #define SND_EFW_RESPONSE_MAXIMUM_BYTES 0x200U |
| 51 | |
| 52 | struct snd_efw_phys_grp { |
| 53 | u8 type; /* see enum snd_efw_grp_type */ |
| 54 | u8 count; |
| 55 | } __packed; |
Takashi Sakamoto | b5b0433 | 2014-04-25 22:45:00 +0900 | [diff] [blame] | 56 | |
| 57 | struct snd_efw { |
| 58 | struct snd_card *card; |
| 59 | struct fw_unit *unit; |
| 60 | int card_index; |
| 61 | |
| 62 | struct mutex mutex; |
| 63 | spinlock_t lock; |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 64 | |
| 65 | /* for transaction */ |
| 66 | u32 seqnum; |
| 67 | bool resp_addr_changable; |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 68 | |
Takashi Sakamoto | 6970223 | 2014-04-25 22:45:05 +0900 | [diff] [blame] | 69 | /* for quirks */ |
| 70 | bool is_af9; |
Takashi Sakamoto | d9cd006 | 2014-04-25 22:45:06 +0900 | [diff] [blame] | 71 | u32 firmware_version; |
Takashi Sakamoto | 6970223 | 2014-04-25 22:45:05 +0900 | [diff] [blame] | 72 | |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 73 | unsigned int midi_in_ports; |
| 74 | unsigned int midi_out_ports; |
| 75 | |
| 76 | unsigned int supported_sampling_rate; |
| 77 | unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES]; |
| 78 | unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES]; |
| 79 | |
| 80 | struct amdtp_stream *master; |
| 81 | struct amdtp_stream tx_stream; |
| 82 | struct amdtp_stream rx_stream; |
| 83 | struct cmp_connection out_conn; |
| 84 | struct cmp_connection in_conn; |
| 85 | atomic_t capture_substreams; |
| 86 | atomic_t playback_substreams; |
Takashi Sakamoto | 6a22683 | 2014-04-25 22:45:08 +0900 | [diff] [blame] | 87 | |
| 88 | /* hardware metering parameters */ |
| 89 | unsigned int phys_out; |
| 90 | unsigned int phys_in; |
| 91 | unsigned int phys_out_grp_count; |
| 92 | unsigned int phys_in_grp_count; |
| 93 | struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS]; |
| 94 | struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS]; |
Takashi Sakamoto | 594ddce | 2014-04-25 22:45:12 +0900 | [diff] [blame^] | 95 | |
| 96 | /* for uapi */ |
| 97 | int dev_lock_count; |
| 98 | bool dev_lock_changed; |
| 99 | wait_queue_head_t hwdep_wait; |
Takashi Sakamoto | b5b0433 | 2014-04-25 22:45:00 +0900 | [diff] [blame] | 100 | }; |
| 101 | |
Takashi Sakamoto | bde8a8f | 2014-04-25 22:45:01 +0900 | [diff] [blame] | 102 | struct snd_efw_transaction { |
| 103 | __be32 length; |
| 104 | __be32 version; |
| 105 | __be32 seqnum; |
| 106 | __be32 category; |
| 107 | __be32 command; |
| 108 | __be32 status; |
| 109 | __be32 params[0]; |
| 110 | }; |
| 111 | int snd_efw_transaction_run(struct fw_unit *unit, |
| 112 | const void *cmd, unsigned int cmd_size, |
| 113 | void *resp, unsigned int resp_size); |
| 114 | int snd_efw_transaction_register(void); |
| 115 | void snd_efw_transaction_unregister(void); |
| 116 | void snd_efw_transaction_bus_reset(struct fw_unit *unit); |
| 117 | |
| 118 | struct snd_efw_hwinfo { |
| 119 | u32 flags; |
| 120 | u32 guid_hi; |
| 121 | u32 guid_lo; |
| 122 | u32 type; |
| 123 | u32 version; |
| 124 | char vendor_name[HWINFO_NAME_SIZE_BYTES]; |
| 125 | char model_name[HWINFO_NAME_SIZE_BYTES]; |
| 126 | u32 supported_clocks; |
| 127 | u32 amdtp_rx_pcm_channels; |
| 128 | u32 amdtp_tx_pcm_channels; |
| 129 | u32 phys_out; |
| 130 | u32 phys_in; |
| 131 | u32 phys_out_grp_count; |
| 132 | struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS]; |
| 133 | u32 phys_in_grp_count; |
| 134 | struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS]; |
| 135 | u32 midi_out_ports; |
| 136 | u32 midi_in_ports; |
| 137 | u32 max_sample_rate; |
| 138 | u32 min_sample_rate; |
| 139 | u32 dsp_version; |
| 140 | u32 arm_version; |
| 141 | u32 mixer_playback_channels; |
| 142 | u32 mixer_capture_channels; |
| 143 | u32 fpga_version; |
| 144 | u32 amdtp_rx_pcm_channels_2x; |
| 145 | u32 amdtp_tx_pcm_channels_2x; |
| 146 | u32 amdtp_rx_pcm_channels_4x; |
| 147 | u32 amdtp_tx_pcm_channels_4x; |
| 148 | u32 reserved[16]; |
| 149 | } __packed; |
| 150 | enum snd_efw_grp_type { |
| 151 | SND_EFW_CH_TYPE_ANALOG = 0, |
| 152 | SND_EFW_CH_TYPE_SPDIF = 1, |
| 153 | SND_EFW_CH_TYPE_ADAT = 2, |
| 154 | SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3, |
| 155 | SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4, |
| 156 | SND_EFW_CH_TYPE_HEADPHONES = 5, |
| 157 | SND_EFW_CH_TYPE_I2S = 6, |
| 158 | SND_EFW_CH_TYPE_GUITAR = 7, |
| 159 | SND_EFW_CH_TYPE_PIEZO_GUITAR = 8, |
| 160 | SND_EFW_CH_TYPE_GUITAR_STRING = 9, |
| 161 | SND_EFW_CH_TYPE_VIRTUAL = 0x10000, |
| 162 | SND_EFW_CH_TYPE_DUMMY |
| 163 | }; |
| 164 | struct snd_efw_phys_meters { |
| 165 | u32 status; /* guitar state/midi signal/clock input detect */ |
| 166 | u32 reserved0; |
| 167 | u32 reserved1; |
| 168 | u32 reserved2; |
| 169 | u32 reserved3; |
| 170 | u32 out_meters; |
| 171 | u32 in_meters; |
| 172 | u32 reserved4; |
| 173 | u32 reserved5; |
| 174 | u32 values[0]; |
| 175 | } __packed; |
| 176 | enum snd_efw_clock_source { |
| 177 | SND_EFW_CLOCK_SOURCE_INTERNAL = 0, |
| 178 | SND_EFW_CLOCK_SOURCE_SYTMATCH = 1, |
| 179 | SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2, |
| 180 | SND_EFW_CLOCK_SOURCE_SPDIF = 3, |
| 181 | SND_EFW_CLOCK_SOURCE_ADAT_1 = 4, |
| 182 | SND_EFW_CLOCK_SOURCE_ADAT_2 = 5, |
| 183 | SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */ |
| 184 | }; |
| 185 | enum snd_efw_transport_mode { |
| 186 | SND_EFW_TRANSPORT_MODE_WINDOWS = 0, |
| 187 | SND_EFW_TRANSPORT_MODE_IEC61883 = 1, |
| 188 | }; |
| 189 | int snd_efw_command_set_resp_addr(struct snd_efw *efw, |
| 190 | u16 addr_high, u32 addr_low); |
| 191 | int snd_efw_command_set_tx_mode(struct snd_efw *efw, unsigned int mode); |
| 192 | int snd_efw_command_get_hwinfo(struct snd_efw *efw, |
| 193 | struct snd_efw_hwinfo *hwinfo); |
| 194 | int snd_efw_command_get_phys_meters(struct snd_efw *efw, |
| 195 | struct snd_efw_phys_meters *meters, |
| 196 | unsigned int len); |
| 197 | int snd_efw_command_get_clock_source(struct snd_efw *efw, |
| 198 | enum snd_efw_clock_source *source); |
| 199 | int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate); |
| 200 | int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate); |
| 201 | |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 202 | int snd_efw_stream_init_duplex(struct snd_efw *efw); |
| 203 | int snd_efw_stream_start_duplex(struct snd_efw *efw, int sampling_rate); |
| 204 | void snd_efw_stream_stop_duplex(struct snd_efw *efw); |
| 205 | void snd_efw_stream_update_duplex(struct snd_efw *efw); |
| 206 | void snd_efw_stream_destroy_duplex(struct snd_efw *efw); |
Takashi Sakamoto | 594ddce | 2014-04-25 22:45:12 +0900 | [diff] [blame^] | 207 | void snd_efw_stream_lock_changed(struct snd_efw *efw); |
| 208 | int snd_efw_stream_lock_try(struct snd_efw *efw); |
| 209 | void snd_efw_stream_lock_release(struct snd_efw *efw); |
Takashi Sakamoto | 315fd41 | 2014-04-25 22:45:02 +0900 | [diff] [blame] | 210 | |
Takashi Sakamoto | 6a22683 | 2014-04-25 22:45:08 +0900 | [diff] [blame] | 211 | void snd_efw_proc_init(struct snd_efw *efw); |
| 212 | |
Takashi Sakamoto | a63d3ff | 2014-04-25 22:45:09 +0900 | [diff] [blame] | 213 | int snd_efw_create_midi_devices(struct snd_efw *efw); |
| 214 | |
Takashi Sakamoto | aa02bb6 | 2014-04-25 22:45:11 +0900 | [diff] [blame] | 215 | int snd_efw_create_pcm_devices(struct snd_efw *efw); |
| 216 | int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode); |
| 217 | |
Takashi Sakamoto | 594ddce | 2014-04-25 22:45:12 +0900 | [diff] [blame^] | 218 | int snd_efw_create_hwdep_device(struct snd_efw *efw); |
| 219 | |
Takashi Sakamoto | b5b0433 | 2014-04-25 22:45:00 +0900 | [diff] [blame] | 220 | #define SND_EFW_DEV_ENTRY(vendor, model) \ |
| 221 | { \ |
| 222 | .match_flags = IEEE1394_MATCH_VENDOR_ID | \ |
| 223 | IEEE1394_MATCH_MODEL_ID, \ |
| 224 | .vendor_id = vendor,\ |
| 225 | .model_id = model \ |
| 226 | } |
| 227 | |
| 228 | #endif |