blob: 30ab77e924f7f68f9b939a230109152722ad9057 [file] [log] [blame]
Takashi Sakamotoc0949b22015-10-01 22:02:11 +09001/*
2 * tascam.h - a part of driver for TASCAM FireWire series
3 *
4 * Copyright (c) 2015 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#ifndef SOUND_TASCAM_H_INCLUDED
10#define SOUND_TASCAM_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
21#include <sound/core.h>
22#include <sound/initval.h>
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +090023#include <sound/info.h>
Takashi Sakamoto47faeea2015-10-01 22:02:14 +090024#include <sound/pcm.h>
25#include <sound/pcm_params.h>
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090026#include <sound/firewire.h>
27#include <sound/hwdep.h>
Takashi Sakamoto107cc012015-10-12 19:10:21 +090028#include <sound/rawmidi.h>
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090029
30#include "../lib.h"
Takashi Sakamoto47faeea2015-10-01 22:02:14 +090031#include "../amdtp-stream.h"
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090032#include "../iso-resources.h"
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090033
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090034struct snd_tscm_spec {
35 const char *const name;
36 bool has_adat;
37 bool has_spdif;
38 unsigned int pcm_capture_analog_channels;
39 unsigned int pcm_playback_analog_channels;
40 unsigned int midi_capture_ports;
41 unsigned int midi_playback_ports;
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090042};
43
Takashi Sakamoto107cc012015-10-12 19:10:21 +090044#define TSCM_MIDI_IN_PORT_MAX 4
45#define TSCM_MIDI_OUT_PORT_MAX 4
46
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090047struct snd_tscm {
48 struct snd_card *card;
49 struct fw_unit *unit;
50
51 struct mutex mutex;
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090052 spinlock_t lock;
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090053
54 const struct snd_tscm_spec *spec;
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090055
56 struct fw_iso_resources tx_resources;
57 struct fw_iso_resources rx_resources;
58 struct amdtp_stream tx_stream;
59 struct amdtp_stream rx_stream;
60 unsigned int substreams_counter;
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090061
62 int dev_lock_count;
63 bool dev_lock_changed;
64 wait_queue_head_t hwdep_wait;
Takashi Sakamoto107cc012015-10-12 19:10:21 +090065
66 /* For MIDI message incoming transactions. */
67 struct fw_address_handler async_handler;
68 struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
Takashi Sakamoto3beab0f2015-10-12 19:10:22 +090069
70 /* For MIDI message outgoing transactions. */
71 struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
72 u8 running_status[TSCM_MIDI_OUT_PORT_MAX];
73 bool on_sysex[TSCM_MIDI_OUT_PORT_MAX];
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090074};
75
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +090076#define TSCM_ADDR_BASE 0xffff00000000ull
77
78#define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
79#define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
80#define TSCM_OFFSET_FIRMWARE_ARM 0x0008
81#define TSCM_OFFSET_FIRMWARE_HW 0x000c
82
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090083#define TSCM_OFFSET_ISOC_TX_CH 0x0200
84#define TSCM_OFFSET_UNKNOWN 0x0204
85#define TSCM_OFFSET_START_STREAMING 0x0208
86#define TSCM_OFFSET_ISOC_RX_CH 0x020c
87#define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
88#define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
89#define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
90#define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
91#define TSCM_OFFSET_ISOC_TX_ON 0x0220
92/* Unknown 0x0224 */
93#define TSCM_OFFSET_CLOCK_STATUS 0x0228
94#define TSCM_OFFSET_SET_OPTION 0x022c
95
Takashi Sakamoto107cc012015-10-12 19:10:21 +090096#define TSCM_OFFSET_MIDI_TX_ON 0x0300
97#define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
98#define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
99
Takashi Sakamotoe65e2cb2015-10-12 19:10:24 +0900100#define TSCM_OFFSET_LED_POWER 0x0404
101
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900102#define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
103
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900104enum snd_tscm_clock {
105 SND_TSCM_CLOCK_INTERNAL = 0,
106 SND_TSCM_CLOCK_WORD = 1,
107 SND_TSCM_CLOCK_SPDIF = 2,
108 SND_TSCM_CLOCK_ADAT = 3,
109};
110
Takashi Sakamoto47faeea2015-10-01 22:02:14 +0900111int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
112 enum amdtp_stream_direction dir, unsigned int pcm_channels);
113int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
114int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
115 struct snd_pcm_runtime *runtime);
116void amdtp_tscm_set_pcm_format(struct amdtp_stream *s, snd_pcm_format_t format);
117
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900118int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
119int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
120 enum snd_tscm_clock *clock);
121int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
122void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
123void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
124int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
125void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
126
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +0900127void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
128int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
129void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
130
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900131int snd_tscm_transaction_register(struct snd_tscm *tscm);
132int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
133void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
134
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +0900135void snd_tscm_proc_init(struct snd_tscm *tscm);
136
Takashi Sakamotoe453df42015-10-01 22:02:16 +0900137int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
138
Takashi Sakamoto0db18e72015-10-12 19:10:23 +0900139int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
140
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +0900141int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
142
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900143#endif