Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * tascam.h - a part of driver for TASCAM FireWire series
0004  *
0005  * Copyright (c) 2015 Takashi Sakamoto
0006  */
0007 
0008 #ifndef SOUND_TASCAM_H_INCLUDED
0009 #define SOUND_TASCAM_H_INCLUDED
0010 
0011 #include <linux/device.h>
0012 #include <linux/firewire.h>
0013 #include <linux/firewire-constants.h>
0014 #include <linux/module.h>
0015 #include <linux/mod_devicetable.h>
0016 #include <linux/mutex.h>
0017 #include <linux/slab.h>
0018 #include <linux/compat.h>
0019 #include <linux/sched/signal.h>
0020 
0021 #include <sound/core.h>
0022 #include <sound/initval.h>
0023 #include <sound/info.h>
0024 #include <sound/pcm.h>
0025 #include <sound/pcm_params.h>
0026 #include <sound/firewire.h>
0027 #include <sound/hwdep.h>
0028 #include <sound/rawmidi.h>
0029 
0030 #include "../lib.h"
0031 #include "../amdtp-stream.h"
0032 #include "../iso-resources.h"
0033 
0034 struct snd_tscm_spec {
0035     const char *const name;
0036     bool has_adat;
0037     bool has_spdif;
0038     unsigned int pcm_capture_analog_channels;
0039     unsigned int pcm_playback_analog_channels;
0040     unsigned int midi_capture_ports;
0041     unsigned int midi_playback_ports;
0042 };
0043 
0044 #define TSCM_MIDI_IN_PORT_MAX   4
0045 #define TSCM_MIDI_OUT_PORT_MAX  4
0046 
0047 struct snd_fw_async_midi_port {
0048     struct fw_device *parent;
0049     struct work_struct work;
0050     bool idling;
0051     ktime_t next_ktime;
0052     bool error;
0053 
0054     struct fw_transaction transaction;
0055 
0056     u8 buf[4];
0057     u8 running_status;
0058     bool on_sysex;
0059 
0060     struct snd_rawmidi_substream *substream;
0061     int consume_bytes;
0062 };
0063 
0064 #define SND_TSCM_QUEUE_COUNT    16
0065 
0066 struct snd_tscm {
0067     struct snd_card *card;
0068     struct fw_unit *unit;
0069 
0070     struct mutex mutex;
0071     spinlock_t lock;
0072 
0073     const struct snd_tscm_spec *spec;
0074 
0075     struct fw_iso_resources tx_resources;
0076     struct fw_iso_resources rx_resources;
0077     struct amdtp_stream tx_stream;
0078     struct amdtp_stream rx_stream;
0079     unsigned int substreams_counter;
0080 
0081     int dev_lock_count;
0082     bool dev_lock_changed;
0083     wait_queue_head_t hwdep_wait;
0084 
0085     /* For MIDI message incoming transactions. */
0086     struct fw_address_handler async_handler;
0087     struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
0088 
0089     /* For MIDI message outgoing transactions. */
0090     struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
0091 
0092     // A cache of status information in tx isoc packets.
0093     __be32 state[SNDRV_FIREWIRE_TASCAM_STATE_COUNT];
0094     struct snd_hwdep *hwdep;
0095     struct snd_firewire_tascam_change queue[SND_TSCM_QUEUE_COUNT];
0096     unsigned int pull_pos;
0097     unsigned int push_pos;
0098 
0099     struct amdtp_domain domain;
0100     bool need_long_tx_init_skip;
0101 };
0102 
0103 #define TSCM_ADDR_BASE          0xffff00000000ull
0104 
0105 #define TSCM_OFFSET_FIRMWARE_REGISTER   0x0000
0106 #define TSCM_OFFSET_FIRMWARE_FPGA   0x0004
0107 #define TSCM_OFFSET_FIRMWARE_ARM    0x0008
0108 #define TSCM_OFFSET_FIRMWARE_HW     0x000c
0109 
0110 #define TSCM_OFFSET_ISOC_TX_CH      0x0200
0111 #define TSCM_OFFSET_UNKNOWN     0x0204
0112 #define TSCM_OFFSET_START_STREAMING 0x0208
0113 #define TSCM_OFFSET_ISOC_RX_CH      0x020c
0114 #define TSCM_OFFSET_ISOC_RX_ON      0x0210  /* Little conviction. */
0115 #define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
0116 #define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
0117 #define TSCM_OFFSET_MULTIPLEX_MODE  0x021c
0118 #define TSCM_OFFSET_ISOC_TX_ON      0x0220
0119 /* Unknown              0x0224 */
0120 #define TSCM_OFFSET_CLOCK_STATUS    0x0228
0121 #define TSCM_OFFSET_SET_OPTION      0x022c
0122 
0123 #define TSCM_OFFSET_MIDI_TX_ON      0x0300
0124 #define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
0125 #define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
0126 
0127 #define TSCM_OFFSET_LED_POWER       0x0404
0128 
0129 #define TSCM_OFFSET_MIDI_RX_QUAD    0x4000
0130 
0131 // Although FE-8 supports the above registers, it has no I/O interfaces for
0132 // audio samples and music messages. Otherwise it supports another notification
0133 // for status and control message as well as LED brightening. The message
0134 // consists of quadlet-aligned data up to 32 quadlets. The first byte of message
0135 // is fixed to 0x40. The second byte is between 0x00 to 0x1f and represent each
0136 // control:
0137 //   fader: 0x00-0x07
0138 //   button:    0x0d, 0x0e
0139 //   knob:  0x14-0x1b
0140 //   sensing:   0x0b
0141 //
0142 // The rest two bytes represent state of the controls; e.g. current value for
0143 // fader and knob, bitmasks for button and sensing.
0144 // Just after turning on, 32 quadlets messages with 0x00-0x1f are immediately
0145 // sent in one transaction. After, several quadlets are sent in one transaction.
0146 //
0147 // TSCM_OFFSET_FE8_CTL_TX_ON        0x0310
0148 // TSCM_OFFSET_FE8_CTL_TX_ADDR_HI   0x0314
0149 // TSCM_OFFSET_FE8_CTL_TX_ADDR_LO   0x0318
0150 
0151 enum snd_tscm_clock {
0152     SND_TSCM_CLOCK_INTERNAL = 0,
0153     SND_TSCM_CLOCK_WORD = 1,
0154     SND_TSCM_CLOCK_SPDIF    = 2,
0155     SND_TSCM_CLOCK_ADAT = 3,
0156 };
0157 
0158 int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
0159           enum amdtp_stream_direction dir, unsigned int pcm_channels);
0160 int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
0161 int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
0162                       struct snd_pcm_runtime *runtime);
0163 
0164 int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
0165 int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
0166                   enum snd_tscm_clock *clock);
0167 int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
0168 void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
0169 void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
0170 int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
0171                    unsigned int frames_per_period,
0172                    unsigned int frames_per_buffer);
0173 int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
0174 void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
0175 
0176 void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
0177 int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
0178 void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
0179 
0180 void snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port);
0181 
0182 static inline void
0183 snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
0184                struct snd_rawmidi_substream *substream)
0185 {
0186     if (!port->error) {
0187         port->substream = substream;
0188         schedule_work(&port->work);
0189     }
0190 }
0191 
0192 static inline void
0193 snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
0194 {
0195     port->substream = NULL;
0196     cancel_work_sync(&port->work);
0197     port->error = false;
0198 }
0199 
0200 int snd_tscm_transaction_register(struct snd_tscm *tscm);
0201 int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
0202 void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
0203 
0204 void snd_tscm_proc_init(struct snd_tscm *tscm);
0205 
0206 int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
0207 
0208 int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
0209 
0210 int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
0211 
0212 #endif