linux/sound/firewire/fireface/ff.h
<<
>>
Prefs
   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>
  20#include <linux/sched/signal.h>
  21
  22#include <sound/core.h>
  23#include <sound/info.h>
  24#include <sound/rawmidi.h>
  25#include <sound/pcm.h>
  26#include <sound/pcm_params.h>
  27#include <sound/hwdep.h>
  28#include <sound/firewire.h>
  29
  30#include "../lib.h"
  31#include "../amdtp-stream.h"
  32#include "../iso-resources.h"
  33
  34#define SND_FF_MAXIMIM_MIDI_QUADS       9
  35#define SND_FF_IN_MIDI_PORTS            2
  36#define SND_FF_OUT_MIDI_PORTS           2
  37
  38enum snd_ff_stream_mode {
  39        SND_FF_STREAM_MODE_LOW = 0,
  40        SND_FF_STREAM_MODE_MID,
  41        SND_FF_STREAM_MODE_HIGH,
  42        SND_FF_STREAM_MODE_COUNT,
  43};
  44
  45struct snd_ff_protocol;
  46struct snd_ff_spec {
  47        const char *const name;
  48
  49        const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
  50        const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
  51
  52        unsigned int midi_in_ports;
  53        unsigned int midi_out_ports;
  54
  55        const struct snd_ff_protocol *protocol;
  56        u64 midi_high_addr;
  57        u8 midi_addr_range;
  58        u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
  59};
  60
  61struct snd_ff {
  62        struct snd_card *card;
  63        struct fw_unit *unit;
  64        struct mutex mutex;
  65        spinlock_t lock;
  66
  67        bool registered;
  68        struct delayed_work dwork;
  69
  70        const struct snd_ff_spec *spec;
  71
  72        /* To handle MIDI tx. */
  73        struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
  74        struct fw_address_handler async_handler;
  75
  76        /* TO handle MIDI rx. */
  77        struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
  78        bool on_sysex[SND_FF_OUT_MIDI_PORTS];
  79        __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
  80        struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
  81        struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
  82        ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
  83        bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
  84        unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
  85
  86        unsigned int substreams_counter;
  87        struct amdtp_stream tx_stream;
  88        struct amdtp_stream rx_stream;
  89        struct fw_iso_resources tx_resources;
  90        struct fw_iso_resources rx_resources;
  91
  92        int dev_lock_count;
  93        bool dev_lock_changed;
  94        wait_queue_head_t hwdep_wait;
  95};
  96
  97enum snd_ff_clock_src {
  98        SND_FF_CLOCK_SRC_INTERNAL,
  99        SND_FF_CLOCK_SRC_SPDIF,
 100        SND_FF_CLOCK_SRC_ADAT1,
 101        SND_FF_CLOCK_SRC_ADAT2,
 102        SND_FF_CLOCK_SRC_WORD,
 103        SND_FF_CLOCK_SRC_LTC,
 104        /* TODO: perhaps TCO exists. */
 105};
 106
 107struct snd_ff_protocol {
 108        void (*handle_midi_msg)(struct snd_ff *ff, unsigned int offset,
 109                                __le32 *buf, size_t length);
 110        int (*fill_midi_msg)(struct snd_ff *ff,
 111                             struct snd_rawmidi_substream *substream,
 112                             unsigned int port);
 113        int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
 114                         enum snd_ff_clock_src *src);
 115        int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
 116        int (*begin_session)(struct snd_ff *ff, unsigned int rate);
 117        void (*finish_session)(struct snd_ff *ff);
 118        void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
 119};
 120
 121extern const struct snd_ff_protocol snd_ff_protocol_ff800;
 122extern const struct snd_ff_protocol snd_ff_protocol_ff400;
 123extern const struct snd_ff_protocol snd_ff_protocol_latter;
 124
 125int snd_ff_transaction_register(struct snd_ff *ff);
 126int snd_ff_transaction_reregister(struct snd_ff *ff);
 127void snd_ff_transaction_unregister(struct snd_ff *ff);
 128
 129int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
 130                            unsigned int pcm_channels);
 131int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
 132                                    struct snd_pcm_runtime *runtime);
 133int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
 134                  enum amdtp_stream_direction dir);
 135
 136int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
 137                                      enum snd_ff_stream_mode *mode);
 138int snd_ff_stream_init_duplex(struct snd_ff *ff);
 139void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
 140int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
 141void snd_ff_stream_stop_duplex(struct snd_ff *ff);
 142void snd_ff_stream_update_duplex(struct snd_ff *ff);
 143
 144void snd_ff_stream_lock_changed(struct snd_ff *ff);
 145int snd_ff_stream_lock_try(struct snd_ff *ff);
 146void snd_ff_stream_lock_release(struct snd_ff *ff);
 147
 148void snd_ff_proc_init(struct snd_ff *ff);
 149const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
 150
 151int snd_ff_create_midi_devices(struct snd_ff *ff);
 152
 153int snd_ff_create_pcm_devices(struct snd_ff *ff);
 154
 155int snd_ff_create_hwdep_devices(struct snd_ff *ff);
 156
 157#endif
 158