blob: a5bd167eb5d99232d2e47449ca1030877c23a738 [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>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010020#include <linux/sched/signal.h>
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090021
22#include <sound/core.h>
23#include <sound/initval.h>
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +090024#include <sound/info.h>
Takashi Sakamoto47faeea2015-10-01 22:02:14 +090025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090027#include <sound/firewire.h>
28#include <sound/hwdep.h>
Takashi Sakamoto107cc012015-10-12 19:10:21 +090029#include <sound/rawmidi.h>
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090030
31#include "../lib.h"
Takashi Sakamoto47faeea2015-10-01 22:02:14 +090032#include "../amdtp-stream.h"
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090033#include "../iso-resources.h"
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090034
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090035struct snd_tscm_spec {
36 const char *const name;
37 bool has_adat;
38 bool has_spdif;
39 unsigned int pcm_capture_analog_channels;
40 unsigned int pcm_playback_analog_channels;
41 unsigned int midi_capture_ports;
42 unsigned int midi_playback_ports;
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090043};
44
Takashi Sakamoto107cc012015-10-12 19:10:21 +090045#define TSCM_MIDI_IN_PORT_MAX 4
46#define TSCM_MIDI_OUT_PORT_MAX 4
47
Takashi Sakamoto531f4712017-04-14 16:46:25 +090048struct snd_fw_async_midi_port {
49 struct fw_device *parent;
50 struct work_struct work;
51 bool idling;
52 ktime_t next_ktime;
53 bool error;
54
Takashi Sakamoto531f4712017-04-14 16:46:25 +090055 struct fw_transaction transaction;
56
Takashi Sakamoto98a00d32017-04-14 16:46:29 +090057 u8 buf[4];
Takashi Sakamoto1f942052017-04-14 16:46:31 +090058 u8 running_status;
59 bool on_sysex;
Takashi Sakamoto531f4712017-04-14 16:46:25 +090060
61 struct snd_rawmidi_substream *substream;
Takashi Sakamoto531f4712017-04-14 16:46:25 +090062 int consume_bytes;
63};
64
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090065struct snd_tscm {
66 struct snd_card *card;
67 struct fw_unit *unit;
68
69 struct mutex mutex;
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090070 spinlock_t lock;
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090071
Takashi Sakamotob6103862016-03-31 08:47:09 +090072 bool registered;
73 struct delayed_work dwork;
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090074 const struct snd_tscm_spec *spec;
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090075
76 struct fw_iso_resources tx_resources;
77 struct fw_iso_resources rx_resources;
78 struct amdtp_stream tx_stream;
79 struct amdtp_stream rx_stream;
80 unsigned int substreams_counter;
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +090081
82 int dev_lock_count;
83 bool dev_lock_changed;
84 wait_queue_head_t hwdep_wait;
Takashi Sakamoto107cc012015-10-12 19:10:21 +090085
86 /* For MIDI message incoming transactions. */
87 struct fw_address_handler async_handler;
88 struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
Takashi Sakamoto3beab0f2015-10-12 19:10:22 +090089
90 /* For MIDI message outgoing transactions. */
91 struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090092};
93
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +090094#define TSCM_ADDR_BASE 0xffff00000000ull
95
96#define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
97#define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
98#define TSCM_OFFSET_FIRMWARE_ARM 0x0008
99#define TSCM_OFFSET_FIRMWARE_HW 0x000c
100
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900101#define TSCM_OFFSET_ISOC_TX_CH 0x0200
102#define TSCM_OFFSET_UNKNOWN 0x0204
103#define TSCM_OFFSET_START_STREAMING 0x0208
104#define TSCM_OFFSET_ISOC_RX_CH 0x020c
105#define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
106#define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
107#define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
108#define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
109#define TSCM_OFFSET_ISOC_TX_ON 0x0220
110/* Unknown 0x0224 */
111#define TSCM_OFFSET_CLOCK_STATUS 0x0228
112#define TSCM_OFFSET_SET_OPTION 0x022c
113
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900114#define TSCM_OFFSET_MIDI_TX_ON 0x0300
115#define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
116#define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
117
Takashi Sakamotoe65e2cb2015-10-12 19:10:24 +0900118#define TSCM_OFFSET_LED_POWER 0x0404
119
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900120#define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
121
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900122enum snd_tscm_clock {
123 SND_TSCM_CLOCK_INTERNAL = 0,
124 SND_TSCM_CLOCK_WORD = 1,
125 SND_TSCM_CLOCK_SPDIF = 2,
126 SND_TSCM_CLOCK_ADAT = 3,
127};
128
Takashi Sakamoto47faeea2015-10-01 22:02:14 +0900129int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
130 enum amdtp_stream_direction dir, unsigned int pcm_channels);
131int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
132int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
133 struct snd_pcm_runtime *runtime);
Takashi Sakamoto47faeea2015-10-01 22:02:14 +0900134
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900135int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
136int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
137 enum snd_tscm_clock *clock);
138int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
139void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
140void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
141int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
142void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
143
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +0900144void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
145int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
146void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
147
Takashi Sakamoto3e7dc652017-04-14 16:46:30 +0900148void snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port);
Takashi Sakamoto531f4712017-04-14 16:46:25 +0900149
150static inline void
151snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
152 struct snd_rawmidi_substream *substream)
153{
154 if (!port->error) {
155 port->substream = substream;
156 schedule_work(&port->work);
157 }
158}
159
160static inline void
161snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
162{
163 port->substream = NULL;
Takashi Sakamoto98a00d32017-04-14 16:46:29 +0900164 cancel_work_sync(&port->work);
Takashi Sakamoto531f4712017-04-14 16:46:25 +0900165 port->error = false;
166}
167
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900168int snd_tscm_transaction_register(struct snd_tscm *tscm);
169int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
170void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
171
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +0900172void snd_tscm_proc_init(struct snd_tscm *tscm);
173
Takashi Sakamotoe453df42015-10-01 22:02:16 +0900174int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
175
Takashi Sakamoto0db18e72015-10-12 19:10:23 +0900176int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
177
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +0900178int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
179
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900180#endif