ALSA: firewire-tascam: register the size of PCM period to AMDTP domain
[linux-2.6-block.git] / sound / firewire / tascam / tascam.h
CommitLineData
da607e19 1/* SPDX-License-Identifier: GPL-2.0-only */
c0949b27
TS
2/*
3 * tascam.h - a part of driver for TASCAM FireWire series
4 *
5 * Copyright (c) 2015 Takashi Sakamoto
c0949b27
TS
6 */
7
8#ifndef SOUND_TASCAM_H_INCLUDED
9#define SOUND_TASCAM_H_INCLUDED
10
11#include <linux/device.h>
12#include <linux/firewire.h>
13#include <linux/firewire-constants.h>
14#include <linux/module.h>
15#include <linux/mod_devicetable.h>
16#include <linux/mutex.h>
17#include <linux/slab.h>
18#include <linux/compat.h>
174cd4b1 19#include <linux/sched/signal.h>
c0949b27
TS
20
21#include <sound/core.h>
22#include <sound/initval.h>
96e5fbb0 23#include <sound/info.h>
47faeea2
TS
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
e5e0c3dd
TS
26#include <sound/firewire.h>
27#include <sound/hwdep.h>
107cc012 28#include <sound/rawmidi.h>
c0949b27
TS
29
30#include "../lib.h"
47faeea2 31#include "../amdtp-stream.h"
35efa5c4 32#include "../iso-resources.h"
c0949b27 33
6f81ba19
TS
34struct 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;
6f81ba19
TS
42};
43
107cc012
TS
44#define TSCM_MIDI_IN_PORT_MAX 4
45#define TSCM_MIDI_OUT_PORT_MAX 4
46
531f4718
TS
47struct snd_fw_async_midi_port {
48 struct fw_device *parent;
49 struct work_struct work;
50 bool idling;
51 ktime_t next_ktime;
52 bool error;
53
531f4718
TS
54 struct fw_transaction transaction;
55
98a00d36 56 u8 buf[4];
1f94205d
TS
57 u8 running_status;
58 bool on_sysex;
531f4718
TS
59
60 struct snd_rawmidi_substream *substream;
531f4718
TS
61 int consume_bytes;
62};
63
d7167422
TS
64#define SND_TSCM_QUEUE_COUNT 16
65
c0949b27
TS
66struct snd_tscm {
67 struct snd_card *card;
68 struct fw_unit *unit;
69
70 struct mutex mutex;
e5e0c3dd 71 spinlock_t lock;
6f81ba19 72
b610386c
TS
73 bool registered;
74 struct delayed_work dwork;
6f81ba19 75 const struct snd_tscm_spec *spec;
35efa5c4
TS
76
77 struct fw_iso_resources tx_resources;
78 struct fw_iso_resources rx_resources;
79 struct amdtp_stream tx_stream;
80 struct amdtp_stream rx_stream;
81 unsigned int substreams_counter;
e5e0c3dd
TS
82
83 int dev_lock_count;
84 bool dev_lock_changed;
85 wait_queue_head_t hwdep_wait;
107cc012
TS
86
87 /* For MIDI message incoming transactions. */
88 struct fw_address_handler async_handler;
89 struct snd_rawmidi_substream *tx_midi_substreams[TSCM_MIDI_IN_PORT_MAX];
3beab0f8
TS
90
91 /* For MIDI message outgoing transactions. */
92 struct snd_fw_async_midi_port out_ports[TSCM_MIDI_OUT_PORT_MAX];
33b2e144
TS
93
94 // A cache of status information in tx isoc packets.
95 __be32 state[SNDRV_FIREWIRE_TASCAM_STATE_COUNT];
d7167422
TS
96 struct snd_hwdep *hwdep;
97 struct snd_firewire_tascam_change queue[SND_TSCM_QUEUE_COUNT];
98 unsigned int pull_pos;
99 unsigned int push_pos;
c281d46a
TS
100
101 struct amdtp_domain domain;
c0949b27
TS
102};
103
96e5fbb0
TS
104#define TSCM_ADDR_BASE 0xffff00000000ull
105
106#define TSCM_OFFSET_FIRMWARE_REGISTER 0x0000
107#define TSCM_OFFSET_FIRMWARE_FPGA 0x0004
108#define TSCM_OFFSET_FIRMWARE_ARM 0x0008
109#define TSCM_OFFSET_FIRMWARE_HW 0x000c
110
35efa5c4
TS
111#define TSCM_OFFSET_ISOC_TX_CH 0x0200
112#define TSCM_OFFSET_UNKNOWN 0x0204
113#define TSCM_OFFSET_START_STREAMING 0x0208
114#define TSCM_OFFSET_ISOC_RX_CH 0x020c
115#define TSCM_OFFSET_ISOC_RX_ON 0x0210 /* Little conviction. */
116#define TSCM_OFFSET_TX_PCM_CHANNELS 0x0214
117#define TSCM_OFFSET_RX_PCM_CHANNELS 0x0218
118#define TSCM_OFFSET_MULTIPLEX_MODE 0x021c
119#define TSCM_OFFSET_ISOC_TX_ON 0x0220
120/* Unknown 0x0224 */
121#define TSCM_OFFSET_CLOCK_STATUS 0x0228
122#define TSCM_OFFSET_SET_OPTION 0x022c
123
107cc012
TS
124#define TSCM_OFFSET_MIDI_TX_ON 0x0300
125#define TSCM_OFFSET_MIDI_TX_ADDR_HI 0x0304
126#define TSCM_OFFSET_MIDI_TX_ADDR_LO 0x0308
127
e65e2cb9
TS
128#define TSCM_OFFSET_LED_POWER 0x0404
129
107cc012
TS
130#define TSCM_OFFSET_MIDI_RX_QUAD 0x4000
131
e6e2fe2b
TS
132// Although FE-8 supports the above registers, it has no I/O interfaces for
133// audio samples and music messages. Otherwise it supports another notification
134// for status and control message as well as LED brightening. The message
135// consists of quadlet-aligned data up to 32 quadlets. The first byte of message
136// is fixed to 0x40. The second byte is between 0x00 to 0x1f and represent each
137// control:
138// fader: 0x00-0x07
139// button: 0x0d, 0x0e
140// knob: 0x14-0x1b
141// sensing: 0x0b
142//
143// The rest two bytes represent state of the controls; e.g. current value for
144// fader and knob, bitmasks for button and sensing.
145// Just after turning on, 32 quadlets messages with 0x00-0x1f are immediately
146// sent in one transaction. After, several quadlets are sent in one transaction.
147//
148// TSCM_OFFSET_FE8_CTL_TX_ON 0x0310
149// TSCM_OFFSET_FE8_CTL_TX_ADDR_HI 0x0314
150// TSCM_OFFSET_FE8_CTL_TX_ADDR_LO 0x0318
151
35efa5c4
TS
152enum snd_tscm_clock {
153 SND_TSCM_CLOCK_INTERNAL = 0,
154 SND_TSCM_CLOCK_WORD = 1,
155 SND_TSCM_CLOCK_SPDIF = 2,
156 SND_TSCM_CLOCK_ADAT = 3,
157};
158
47faeea2
TS
159int amdtp_tscm_init(struct amdtp_stream *s, struct fw_unit *unit,
160 enum amdtp_stream_direction dir, unsigned int pcm_channels);
161int amdtp_tscm_set_parameters(struct amdtp_stream *s, unsigned int rate);
162int amdtp_tscm_add_pcm_hw_constraints(struct amdtp_stream *s,
163 struct snd_pcm_runtime *runtime);
47faeea2 164
35efa5c4
TS
165int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate);
166int snd_tscm_stream_get_clock(struct snd_tscm *tscm,
167 enum snd_tscm_clock *clock);
168int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
169void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
170void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
262542ed
TS
171int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
172 unsigned int frames_per_period);
35efa5c4
TS
173int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
174void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
175
e5e0c3dd
TS
176void snd_tscm_stream_lock_changed(struct snd_tscm *tscm);
177int snd_tscm_stream_lock_try(struct snd_tscm *tscm);
178void snd_tscm_stream_lock_release(struct snd_tscm *tscm);
179
3e7dc65c 180void snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port);
531f4718
TS
181
182static inline void
183snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
184 struct snd_rawmidi_substream *substream)
185{
186 if (!port->error) {
187 port->substream = substream;
188 schedule_work(&port->work);
189 }
190}
191
192static inline void
193snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
194{
195 port->substream = NULL;
98a00d36 196 cancel_work_sync(&port->work);
531f4718
TS
197 port->error = false;
198}
199
107cc012
TS
200int snd_tscm_transaction_register(struct snd_tscm *tscm);
201int snd_tscm_transaction_reregister(struct snd_tscm *tscm);
202void snd_tscm_transaction_unregister(struct snd_tscm *tscm);
203
96e5fbb0
TS
204void snd_tscm_proc_init(struct snd_tscm *tscm);
205
e453df44
TS
206int snd_tscm_create_pcm_devices(struct snd_tscm *tscm);
207
0db18e7e
TS
208int snd_tscm_create_midi_devices(struct snd_tscm *tscm);
209
e5e0c3dd
TS
210int snd_tscm_create_hwdep_device(struct snd_tscm *tscm);
211
c0949b27 212#endif