Linux 4.15.6
[linux/fpc-iii.git] / sound / firewire / digi00x / digi00x-transaction.c
blobaf9bc85047819daed40d8de28e002ab2e24febe5
1 /*
2 * digi00x-transaction.c - a part of driver for Digidesign Digi 002/003 family
4 * Copyright (c) 2014-2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
9 #include <sound/asound.h>
10 #include "digi00x.h"
12 static void handle_unknown_message(struct snd_dg00x *dg00x,
13 unsigned long long offset, __be32 *buf)
15 unsigned long flags;
17 spin_lock_irqsave(&dg00x->lock, flags);
18 dg00x->msg = be32_to_cpu(*buf);
19 spin_unlock_irqrestore(&dg00x->lock, flags);
21 wake_up(&dg00x->hwdep_wait);
24 static void handle_message(struct fw_card *card, struct fw_request *request,
25 int tcode, int destination, int source,
26 int generation, unsigned long long offset,
27 void *data, size_t length, void *callback_data)
29 struct snd_dg00x *dg00x = callback_data;
30 __be32 *buf = (__be32 *)data;
32 fw_send_response(card, request, RCODE_COMPLETE);
34 if (offset == dg00x->async_handler.offset)
35 handle_unknown_message(dg00x, offset, buf);
38 int snd_dg00x_transaction_reregister(struct snd_dg00x *dg00x)
40 struct fw_device *device = fw_parent_device(dg00x->unit);
41 __be32 data[2];
43 /* Unknown. 4bytes. */
44 data[0] = cpu_to_be32((device->card->node_id << 16) |
45 (dg00x->async_handler.offset >> 32));
46 data[1] = cpu_to_be32(dg00x->async_handler.offset);
47 return snd_fw_transaction(dg00x->unit, TCODE_WRITE_BLOCK_REQUEST,
48 DG00X_ADDR_BASE + DG00X_OFFSET_MESSAGE_ADDR,
49 &data, sizeof(data), 0);
52 void snd_dg00x_transaction_unregister(struct snd_dg00x *dg00x)
54 if (dg00x->async_handler.callback_data == NULL)
55 return;
57 fw_core_remove_address_handler(&dg00x->async_handler);
59 dg00x->async_handler.callback_data = NULL;
62 int snd_dg00x_transaction_register(struct snd_dg00x *dg00x)
64 static const struct fw_address_region resp_register_region = {
65 .start = 0xffffe0000000ull,
66 .end = 0xffffe000ffffull,
68 int err;
70 dg00x->async_handler.length = 4;
71 dg00x->async_handler.address_callback = handle_message;
72 dg00x->async_handler.callback_data = dg00x;
74 err = fw_core_add_address_handler(&dg00x->async_handler,
75 &resp_register_region);
76 if (err < 0)
77 return err;
79 err = snd_dg00x_transaction_reregister(dg00x);
80 if (err < 0)
81 snd_dg00x_transaction_unregister(dg00x);
83 return err;