Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * fireworks.h - a part of driver for Fireworks based devices
0004  *
0005  * Copyright (c) 2009-2010 Clemens Ladisch
0006  * Copyright (c) 2013-2014 Takashi Sakamoto
0007  */
0008 #ifndef SOUND_FIREWORKS_H_INCLUDED
0009 #define SOUND_FIREWORKS_H_INCLUDED
0010 
0011 #include <linux/compat.h>
0012 #include <linux/device.h>
0013 #include <linux/firewire.h>
0014 #include <linux/firewire-constants.h>
0015 #include <linux/module.h>
0016 #include <linux/mod_devicetable.h>
0017 #include <linux/delay.h>
0018 #include <linux/slab.h>
0019 #include <linux/sched/signal.h>
0020 
0021 #include <sound/core.h>
0022 #include <sound/initval.h>
0023 #include <sound/pcm.h>
0024 #include <sound/info.h>
0025 #include <sound/rawmidi.h>
0026 #include <sound/pcm_params.h>
0027 #include <sound/firewire.h>
0028 #include <sound/hwdep.h>
0029 
0030 #include "../packets-buffer.h"
0031 #include "../iso-resources.h"
0032 #include "../amdtp-am824.h"
0033 #include "../cmp.h"
0034 #include "../lib.h"
0035 
0036 #define SND_EFW_MAX_MIDI_OUT_PORTS  2
0037 #define SND_EFW_MAX_MIDI_IN_PORTS   2
0038 
0039 #define SND_EFW_MULTIPLIER_MODES    3
0040 #define HWINFO_NAME_SIZE_BYTES      32
0041 #define HWINFO_MAX_CAPS_GROUPS      8
0042 
0043 /*
0044  * This should be greater than maximum bytes for EFW response content.
0045  * Currently response against command for isochronous channel mapping is
0046  * confirmed to be the maximum one. But for flexibility, use maximum data
0047  * payload for asynchronous primary packets at S100 (Cable base rate) in
0048  * IEEE Std 1394-1995.
0049  */
0050 #define SND_EFW_RESPONSE_MAXIMUM_BYTES  0x200U
0051 
0052 extern unsigned int snd_efw_resp_buf_size;
0053 extern bool snd_efw_resp_buf_debug;
0054 
0055 struct snd_efw_phys_grp {
0056     u8 type;    /* see enum snd_efw_grp_type */
0057     u8 count;
0058 } __packed;
0059 
0060 struct snd_efw {
0061     struct snd_card *card;
0062     struct fw_unit *unit;
0063     int card_index;
0064 
0065     struct mutex mutex;
0066     spinlock_t lock;
0067 
0068     /* for transaction */
0069     u32 seqnum;
0070     bool resp_addr_changable;
0071 
0072     /* for quirks */
0073     bool is_af9;
0074     bool is_fireworks3;
0075     u32 firmware_version;
0076 
0077     unsigned int midi_in_ports;
0078     unsigned int midi_out_ports;
0079 
0080     unsigned int supported_sampling_rate;
0081     unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
0082     unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
0083 
0084     struct amdtp_stream tx_stream;
0085     struct amdtp_stream rx_stream;
0086     struct cmp_connection out_conn;
0087     struct cmp_connection in_conn;
0088     unsigned int substreams_counter;
0089 
0090     /* hardware metering parameters */
0091     unsigned int phys_out;
0092     unsigned int phys_in;
0093     unsigned int phys_out_grp_count;
0094     unsigned int phys_in_grp_count;
0095     struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
0096     struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
0097 
0098     /* for uapi */
0099     int dev_lock_count;
0100     bool dev_lock_changed;
0101     wait_queue_head_t hwdep_wait;
0102 
0103     /* response queue */
0104     u8 *resp_buf;
0105     u8 *pull_ptr;
0106     u8 *push_ptr;
0107 
0108     struct amdtp_domain domain;
0109 };
0110 
0111 int snd_efw_transaction_cmd(struct fw_unit *unit,
0112                 const void *cmd, unsigned int size);
0113 int snd_efw_transaction_run(struct fw_unit *unit,
0114                 const void *cmd, unsigned int cmd_size,
0115                 void *resp, unsigned int resp_size);
0116 int snd_efw_transaction_register(void);
0117 void snd_efw_transaction_unregister(void);
0118 void snd_efw_transaction_bus_reset(struct fw_unit *unit);
0119 void snd_efw_transaction_add_instance(struct snd_efw *efw);
0120 void snd_efw_transaction_remove_instance(struct snd_efw *efw);
0121 
0122 struct snd_efw_hwinfo {
0123     u32 flags;
0124     u32 guid_hi;
0125     u32 guid_lo;
0126     u32 type;
0127     u32 version;
0128     char vendor_name[HWINFO_NAME_SIZE_BYTES];
0129     char model_name[HWINFO_NAME_SIZE_BYTES];
0130     u32 supported_clocks;
0131     u32 amdtp_rx_pcm_channels;
0132     u32 amdtp_tx_pcm_channels;
0133     u32 phys_out;
0134     u32 phys_in;
0135     u32 phys_out_grp_count;
0136     struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
0137     u32 phys_in_grp_count;
0138     struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
0139     u32 midi_out_ports;
0140     u32 midi_in_ports;
0141     u32 max_sample_rate;
0142     u32 min_sample_rate;
0143     u32 dsp_version;
0144     u32 arm_version;
0145     u32 mixer_playback_channels;
0146     u32 mixer_capture_channels;
0147     u32 fpga_version;
0148     u32 amdtp_rx_pcm_channels_2x;
0149     u32 amdtp_tx_pcm_channels_2x;
0150     u32 amdtp_rx_pcm_channels_4x;
0151     u32 amdtp_tx_pcm_channels_4x;
0152     u32 reserved[16];
0153 } __packed;
0154 enum snd_efw_grp_type {
0155     SND_EFW_CH_TYPE_ANALOG          = 0,
0156     SND_EFW_CH_TYPE_SPDIF           = 1,
0157     SND_EFW_CH_TYPE_ADAT            = 2,
0158     SND_EFW_CH_TYPE_SPDIF_OR_ADAT       = 3,
0159     SND_EFW_CH_TYPE_ANALOG_MIRRORING    = 4,
0160     SND_EFW_CH_TYPE_HEADPHONES      = 5,
0161     SND_EFW_CH_TYPE_I2S         = 6,
0162     SND_EFW_CH_TYPE_GUITAR          = 7,
0163     SND_EFW_CH_TYPE_PIEZO_GUITAR        = 8,
0164     SND_EFW_CH_TYPE_GUITAR_STRING       = 9,
0165     SND_EFW_CH_TYPE_DUMMY
0166 };
0167 struct snd_efw_phys_meters {
0168     u32 status; /* guitar state/midi signal/clock input detect */
0169     u32 reserved0;
0170     u32 reserved1;
0171     u32 reserved2;
0172     u32 reserved3;
0173     u32 out_meters;
0174     u32 in_meters;
0175     u32 reserved4;
0176     u32 reserved5;
0177     u32 values[];
0178 } __packed;
0179 enum snd_efw_clock_source {
0180     SND_EFW_CLOCK_SOURCE_INTERNAL   = 0,
0181     // Unused.
0182     SND_EFW_CLOCK_SOURCE_WORDCLOCK  = 2,
0183     SND_EFW_CLOCK_SOURCE_SPDIF  = 3,
0184     SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
0185     SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
0186     SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
0187 };
0188 enum snd_efw_transport_mode {
0189     SND_EFW_TRANSPORT_MODE_WINDOWS  = 0,
0190     SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
0191 };
0192 int snd_efw_command_set_resp_addr(struct snd_efw *efw,
0193                   u16 addr_high, u32 addr_low);
0194 int snd_efw_command_set_tx_mode(struct snd_efw *efw,
0195                 enum snd_efw_transport_mode mode);
0196 int snd_efw_command_get_hwinfo(struct snd_efw *efw,
0197                    struct snd_efw_hwinfo *hwinfo);
0198 int snd_efw_command_get_phys_meters(struct snd_efw *efw,
0199                     struct snd_efw_phys_meters *meters,
0200                     unsigned int len);
0201 int snd_efw_command_get_clock_source(struct snd_efw *efw,
0202                      enum snd_efw_clock_source *source);
0203 int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
0204 int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
0205 
0206 int snd_efw_stream_init_duplex(struct snd_efw *efw);
0207 int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate,
0208                   unsigned int frames_per_period,
0209                   unsigned int frames_per_buffer);
0210 int snd_efw_stream_start_duplex(struct snd_efw *efw);
0211 void snd_efw_stream_stop_duplex(struct snd_efw *efw);
0212 void snd_efw_stream_update_duplex(struct snd_efw *efw);
0213 void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
0214 void snd_efw_stream_lock_changed(struct snd_efw *efw);
0215 int snd_efw_stream_lock_try(struct snd_efw *efw);
0216 void snd_efw_stream_lock_release(struct snd_efw *efw);
0217 
0218 void snd_efw_proc_init(struct snd_efw *efw);
0219 
0220 int snd_efw_create_midi_devices(struct snd_efw *efw);
0221 
0222 int snd_efw_create_pcm_devices(struct snd_efw *efw);
0223 int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
0224 
0225 int snd_efw_create_hwdep_device(struct snd_efw *efw);
0226 
0227 #endif