1 // SPDX-License-Identifier: GPL-2.0-only
3 * digi00x-transaction.c - a part of driver for Digidesign Digi 002/003 family
5 * Copyright (c) 2014-2015 Takashi Sakamoto
8 #include <sound/asound.h>
11 static void handle_unknown_message(struct snd_dg00x
*dg00x
,
12 unsigned long long offset
, __be32
*buf
)
16 spin_lock_irqsave(&dg00x
->lock
, flags
);
17 dg00x
->msg
= be32_to_cpu(*buf
);
18 spin_unlock_irqrestore(&dg00x
->lock
, flags
);
20 wake_up(&dg00x
->hwdep_wait
);
23 static void handle_message(struct fw_card
*card
, struct fw_request
*request
,
24 int tcode
, int destination
, int source
,
25 int generation
, unsigned long long offset
,
26 void *data
, size_t length
, void *callback_data
)
28 struct snd_dg00x
*dg00x
= callback_data
;
29 __be32
*buf
= (__be32
*)data
;
31 fw_send_response(card
, request
, RCODE_COMPLETE
);
33 if (offset
== dg00x
->async_handler
.offset
)
34 handle_unknown_message(dg00x
, offset
, buf
);
37 int snd_dg00x_transaction_reregister(struct snd_dg00x
*dg00x
)
39 struct fw_device
*device
= fw_parent_device(dg00x
->unit
);
42 /* Unknown. 4bytes. */
43 data
[0] = cpu_to_be32((device
->card
->node_id
<< 16) |
44 (dg00x
->async_handler
.offset
>> 32));
45 data
[1] = cpu_to_be32(dg00x
->async_handler
.offset
);
46 return snd_fw_transaction(dg00x
->unit
, TCODE_WRITE_BLOCK_REQUEST
,
47 DG00X_ADDR_BASE
+ DG00X_OFFSET_MESSAGE_ADDR
,
48 &data
, sizeof(data
), 0);
51 void snd_dg00x_transaction_unregister(struct snd_dg00x
*dg00x
)
53 if (dg00x
->async_handler
.callback_data
== NULL
)
56 fw_core_remove_address_handler(&dg00x
->async_handler
);
58 dg00x
->async_handler
.callback_data
= NULL
;
61 int snd_dg00x_transaction_register(struct snd_dg00x
*dg00x
)
63 static const struct fw_address_region resp_register_region
= {
64 .start
= 0xffffe0000000ull
,
65 .end
= 0xffffe000ffffull
,
69 dg00x
->async_handler
.length
= 4;
70 dg00x
->async_handler
.address_callback
= handle_message
;
71 dg00x
->async_handler
.callback_data
= dg00x
;
73 err
= fw_core_add_address_handler(&dg00x
->async_handler
,
74 &resp_register_region
);
78 err
= snd_dg00x_transaction_reregister(dg00x
);
80 snd_dg00x_transaction_unregister(dg00x
);