2 * ff-protocol-ff400.c - a part of driver for RME Fireface series
4 * Copyright (c) 2015-2017 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
9 #include <linux/delay.h>
12 #define FF400_STF 0x000080100500ull
13 #define FF400_RX_PACKET_FORMAT 0x000080100504ull
14 #define FF400_ISOC_COMM_START 0x000080100508ull
15 #define FF400_TX_PACKET_FORMAT 0x00008010050cull
16 #define FF400_ISOC_COMM_STOP 0x000080100510ull
18 #define FF400_MIDI_HIGH_ADDR 0x0000801003f4ull
19 #define FF400_MIDI_RX_PORT_0 0x000080180000ull
20 #define FF400_MIDI_RX_PORT_1 0x000080190000ull
22 static int ff400_begin_session(struct snd_ff *ff, unsigned int rate)
27 /* Check whether the given value is supported or not. */
28 for (i = 0; i < CIP_SFC_COUNT; i++) {
29 if (amdtp_rate_table[i] == rate)
32 if (i == CIP_SFC_COUNT)
35 /* Set the number of data blocks transferred in a second. */
36 reg = cpu_to_le32(rate);
37 err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
38 FF400_STF, ®, sizeof(reg), 0);
45 * Set isochronous channel and the number of quadlets of received
48 reg = cpu_to_le32(((ff->rx_stream.data_block_quadlets << 3) << 8) |
49 ff->rx_resources.channel);
50 err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
51 FF400_RX_PACKET_FORMAT, ®, sizeof(reg), 0);
56 * Set isochronous channel and the number of quadlets of transmitted
59 /* TODO: investigate the purpose of this 0x80. */
60 reg = cpu_to_le32((0x80 << 24) |
61 (ff->tx_resources.channel << 5) |
62 (ff->tx_stream.data_block_quadlets));
63 err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
64 FF400_TX_PACKET_FORMAT, ®, sizeof(reg), 0);
68 /* Allow to transmit packets. */
69 reg = cpu_to_le32(0x00000001);
70 return snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
71 FF400_ISOC_COMM_START, ®, sizeof(reg), 0);
74 static void ff400_finish_session(struct snd_ff *ff)
78 reg = cpu_to_le32(0x80000000);
79 snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
80 FF400_ISOC_COMM_STOP, ®, sizeof(reg), 0);
83 static int ff400_switch_fetching_mode(struct snd_ff *ff, bool enable)
89 reg = kcalloc(18, sizeof(__le32), GFP_KERNEL);
95 * Each quadlet is corresponding to data channels in a data
96 * blocks in reverse order. Precisely, quadlets for available
97 * data channels should be enabled. Here, I take second best
98 * to fetch PCM frames from all of data channels regardless of
101 for (i = 0; i < 18; ++i)
102 reg[i] = cpu_to_le32(0x00000001);
105 err = snd_fw_transaction(ff->unit, TCODE_WRITE_BLOCK_REQUEST,
106 SND_FF_REG_FETCH_PCM_FRAMES, reg,
107 sizeof(__le32) * 18, 0);
112 const struct snd_ff_protocol snd_ff_protocol_ff400 = {
113 .begin_session = ff400_begin_session,
114 .finish_session = ff400_finish_session,
115 .switch_fetching_mode = ff400_switch_fetching_mode,
117 .midi_high_addr_reg = FF400_MIDI_HIGH_ADDR,
118 .midi_rx_port_0_reg = FF400_MIDI_RX_PORT_0,
119 .midi_rx_port_1_reg = FF400_MIDI_RX_PORT_1,