^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * digi00x-transaction.c - a part of driver for Digidesign Digi 002/003 family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2014-2015 Takashi Sakamoto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <sound/asound.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "digi00x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static void handle_unknown_message(struct snd_dg00x *dg00x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) unsigned long long offset, __be32 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) spin_lock_irqsave(&dg00x->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) dg00x->msg = be32_to_cpu(*buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) spin_unlock_irqrestore(&dg00x->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) wake_up(&dg00x->hwdep_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static void handle_message(struct fw_card *card, struct fw_request *request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int tcode, int destination, int source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int generation, unsigned long long offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void *data, size_t length, void *callback_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct snd_dg00x *dg00x = callback_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) __be32 *buf = (__be32 *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) fw_send_response(card, request, RCODE_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (offset == dg00x->async_handler.offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) handle_unknown_message(dg00x, offset, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int snd_dg00x_transaction_reregister(struct snd_dg00x *dg00x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct fw_device *device = fw_parent_device(dg00x->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) __be32 data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Unknown. 4bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) data[0] = cpu_to_be32((device->card->node_id << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) (dg00x->async_handler.offset >> 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) data[1] = cpu_to_be32(dg00x->async_handler.offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return snd_fw_transaction(dg00x->unit, TCODE_WRITE_BLOCK_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) DG00X_ADDR_BASE + DG00X_OFFSET_MESSAGE_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) &data, sizeof(data), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void snd_dg00x_transaction_unregister(struct snd_dg00x *dg00x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (dg00x->async_handler.callback_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) fw_core_remove_address_handler(&dg00x->async_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) dg00x->async_handler.callback_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int snd_dg00x_transaction_register(struct snd_dg00x *dg00x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static const struct fw_address_region resp_register_region = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .start = 0xffffe0000000ull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .end = 0xffffe000ffffull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) dg00x->async_handler.length = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) dg00x->async_handler.address_callback = handle_message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dg00x->async_handler.callback_data = dg00x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) err = fw_core_add_address_handler(&dg00x->async_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) &resp_register_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) err = snd_dg00x_transaction_reregister(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) snd_dg00x_transaction_unregister(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }