1e2786ca6STakashi Sakamoto /* 2e2786ca6STakashi Sakamoto * oxfw.h - a part of driver for OXFW970/971 based devices 3e2786ca6STakashi Sakamoto * 4e2786ca6STakashi Sakamoto * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 5e2786ca6STakashi Sakamoto * Licensed under the terms of the GNU General Public License, version 2. 6e2786ca6STakashi Sakamoto */ 7e2786ca6STakashi Sakamoto 8e2786ca6STakashi Sakamoto #include <linux/device.h> 9e2786ca6STakashi Sakamoto #include <linux/firewire.h> 10e2786ca6STakashi Sakamoto #include <linux/firewire-constants.h> 11e2786ca6STakashi Sakamoto #include <linux/module.h> 12e2786ca6STakashi Sakamoto #include <linux/mod_devicetable.h> 13e2786ca6STakashi Sakamoto #include <linux/mutex.h> 14e2786ca6STakashi Sakamoto #include <linux/slab.h> 158985f4acSTakashi Sakamoto #include <linux/compat.h> 16174cd4b1SIngo Molnar #include <linux/sched/signal.h> 17e2786ca6STakashi Sakamoto 18e2786ca6STakashi Sakamoto #include <sound/control.h> 19e2786ca6STakashi Sakamoto #include <sound/core.h> 20e2786ca6STakashi Sakamoto #include <sound/initval.h> 21e2786ca6STakashi Sakamoto #include <sound/pcm.h> 22e2786ca6STakashi Sakamoto #include <sound/pcm_params.h> 233c96101fSTakashi Sakamoto #include <sound/info.h> 2405588d34STakashi Sakamoto #include <sound/rawmidi.h> 258985f4acSTakashi Sakamoto #include <sound/firewire.h> 268985f4acSTakashi Sakamoto #include <sound/hwdep.h> 27e2786ca6STakashi Sakamoto 28e2786ca6STakashi Sakamoto #include "../lib.h" 29e2786ca6STakashi Sakamoto #include "../fcp.h" 30e2786ca6STakashi Sakamoto #include "../packets-buffer.h" 31e2786ca6STakashi Sakamoto #include "../iso-resources.h" 325955815eSTakashi Sakamoto #include "../amdtp-am824.h" 33e2786ca6STakashi Sakamoto #include "../cmp.h" 34e2786ca6STakashi Sakamoto 355cd1d3f4STakashi Sakamoto /* This is an arbitrary number for convinience. */ 365cd1d3f4STakashi Sakamoto #define SND_OXFW_STREAM_FORMAT_ENTRIES 10 37e2786ca6STakashi Sakamoto struct snd_oxfw { 38e2786ca6STakashi Sakamoto struct snd_card *card; 39e2786ca6STakashi Sakamoto struct fw_unit *unit; 40e2786ca6STakashi Sakamoto struct mutex mutex; 4105588d34STakashi Sakamoto spinlock_t lock; 425cd1d3f4STakashi Sakamoto 436c29230eSTakashi Sakamoto bool registered; 446c29230eSTakashi Sakamoto struct delayed_work dwork; 456c29230eSTakashi Sakamoto 4613f3a46dSTakashi Sakamoto bool wrong_dbs; 47b0ac0009STakashi Sakamoto bool has_output; 48b0ac0009STakashi Sakamoto u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES]; 495cd1d3f4STakashi Sakamoto u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES]; 505cd1d3f4STakashi Sakamoto bool assumed; 51b0ac0009STakashi Sakamoto struct cmp_connection out_conn; 52e2786ca6STakashi Sakamoto struct cmp_connection in_conn; 53b0ac0009STakashi Sakamoto struct amdtp_stream tx_stream; 54e2786ca6STakashi Sakamoto struct amdtp_stream rx_stream; 554a0a0472STakashi Sakamoto unsigned int substreams_count; 565cd1d3f4STakashi Sakamoto 5705588d34STakashi Sakamoto unsigned int midi_input_ports; 5805588d34STakashi Sakamoto unsigned int midi_output_ports; 5905588d34STakashi Sakamoto 608985f4acSTakashi Sakamoto int dev_lock_count; 618985f4acSTakashi Sakamoto bool dev_lock_changed; 628985f4acSTakashi Sakamoto wait_queue_head_t hwdep_wait; 6327e66635STakashi Sakamoto 6427e66635STakashi Sakamoto const struct ieee1394_device_id *entry; 65c582cc66STakashi Sakamoto void *spec; 66e2786ca6STakashi Sakamoto }; 67e2786ca6STakashi Sakamoto 685b59d809STakashi Sakamoto /* 695b59d809STakashi Sakamoto * AV/C Stream Format Information Specification 1.1 Working Draft 705b59d809STakashi Sakamoto * (Apr 2005, 1394TA) 715b59d809STakashi Sakamoto */ 725b59d809STakashi Sakamoto int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir, 735b59d809STakashi Sakamoto unsigned int pid, u8 *format, unsigned int len); 745b59d809STakashi Sakamoto int avc_stream_get_format(struct fw_unit *unit, 755b59d809STakashi Sakamoto enum avc_general_plug_dir dir, unsigned int pid, 765b59d809STakashi Sakamoto u8 *buf, unsigned int *len, unsigned int eid); 775b59d809STakashi Sakamoto static inline int 785b59d809STakashi Sakamoto avc_stream_get_format_single(struct fw_unit *unit, 795b59d809STakashi Sakamoto enum avc_general_plug_dir dir, unsigned int pid, 805b59d809STakashi Sakamoto u8 *buf, unsigned int *len) 815b59d809STakashi Sakamoto { 825b59d809STakashi Sakamoto return avc_stream_get_format(unit, dir, pid, buf, len, 0xff); 835b59d809STakashi Sakamoto } 845b59d809STakashi Sakamoto static inline int 855b59d809STakashi Sakamoto avc_stream_get_format_list(struct fw_unit *unit, 865b59d809STakashi Sakamoto enum avc_general_plug_dir dir, unsigned int pid, 875b59d809STakashi Sakamoto u8 *buf, unsigned int *len, 885b59d809STakashi Sakamoto unsigned int eid) 895b59d809STakashi Sakamoto { 905b59d809STakashi Sakamoto return avc_stream_get_format(unit, dir, pid, buf, len, eid); 915b59d809STakashi Sakamoto } 925b59d809STakashi Sakamoto 935b59d809STakashi Sakamoto /* 945b59d809STakashi Sakamoto * AV/C Digital Interface Command Set General Specification 4.2 955b59d809STakashi Sakamoto * (Sep 2004, 1394TA) 965b59d809STakashi Sakamoto */ 975b59d809STakashi Sakamoto int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate, 985b59d809STakashi Sakamoto enum avc_general_plug_dir dir, 995b59d809STakashi Sakamoto unsigned short pid); 1005b59d809STakashi Sakamoto 101779f0dbaSTakashi Sakamoto int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw); 102779f0dbaSTakashi Sakamoto int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw, 103b0ac0009STakashi Sakamoto struct amdtp_stream *stream, 104b0ac0009STakashi Sakamoto unsigned int rate, unsigned int pcm_channels); 105779f0dbaSTakashi Sakamoto void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw); 106779f0dbaSTakashi Sakamoto void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw); 107779f0dbaSTakashi Sakamoto void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw); 1083713d93aSTakashi Sakamoto 1095cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation { 1105cd1d3f4STakashi Sakamoto unsigned int rate; 1115cd1d3f4STakashi Sakamoto unsigned int pcm; 1125cd1d3f4STakashi Sakamoto unsigned int midi; 1135cd1d3f4STakashi Sakamoto }; 1145cd1d3f4STakashi Sakamoto int snd_oxfw_stream_parse_format(u8 *format, 1155cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation *formation); 1165cd1d3f4STakashi Sakamoto int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw, 1175cd1d3f4STakashi Sakamoto enum avc_general_plug_dir dir, 1185cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation *formation); 119b0ac0009STakashi Sakamoto 1205cd1d3f4STakashi Sakamoto int snd_oxfw_stream_discover(struct snd_oxfw *oxfw); 1215cd1d3f4STakashi Sakamoto 1228985f4acSTakashi Sakamoto void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw); 1238985f4acSTakashi Sakamoto int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw); 1248985f4acSTakashi Sakamoto void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw); 1258985f4acSTakashi Sakamoto 1263713d93aSTakashi Sakamoto int snd_oxfw_create_pcm(struct snd_oxfw *oxfw); 12731514bfbSTakashi Sakamoto 1283c96101fSTakashi Sakamoto void snd_oxfw_proc_init(struct snd_oxfw *oxfw); 12905588d34STakashi Sakamoto 13005588d34STakashi Sakamoto int snd_oxfw_create_midi(struct snd_oxfw *oxfw); 1318985f4acSTakashi Sakamoto 1328985f4acSTakashi Sakamoto int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw); 13329aa09acSTakashi Sakamoto 1343e2f4570STakashi Sakamoto int snd_oxfw_add_spkr(struct snd_oxfw *oxfw, bool is_lacie); 1353f47152aSTakashi Sakamoto int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw); 136e3315b43STakashi Sakamoto void snd_oxfw_scs1x_update(struct snd_oxfw *oxfw); 137