sound/firewire/motu/motu-transaction.c

Source file repositories/reference/linux-study-clean/sound/firewire/motu/motu-transaction.c

File Facts

System
Linux kernel
Corpus path
sound/firewire/motu/motu-transaction.c
Extension
.c
Size
3542 bytes
Lines
136
Domain
Driver Families
Bucket
sound/firewire
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * motu-transaction.c - a part of driver for MOTU FireWire series
 *
 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
 */


#include "motu.h"

#define SND_MOTU_ADDR_BASE	0xfffff0000000ULL
#define ASYNC_ADDR_HI  0x0b04
#define ASYNC_ADDR_LO  0x0b08

int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg,
			      size_t size)
{
	int tcode;

	if (size % sizeof(__be32) > 0 || size <= 0)
		return -EINVAL;
	if (size == sizeof(__be32))
		tcode = TCODE_READ_QUADLET_REQUEST;
	else
		tcode = TCODE_READ_BLOCK_REQUEST;

	return snd_fw_transaction(motu->unit, tcode,
				  SND_MOTU_ADDR_BASE + offset, reg, size, 0);
}

int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg,
			       size_t size)
{
	int tcode;

	if (size % sizeof(__be32) > 0 || size <= 0)
		return -EINVAL;
	if (size == sizeof(__be32))
		tcode = TCODE_WRITE_QUADLET_REQUEST;
	else
		tcode = TCODE_WRITE_BLOCK_REQUEST;

	return snd_fw_transaction(motu->unit, tcode,
				  SND_MOTU_ADDR_BASE + offset, reg, size, 0);
}

static void handle_message(struct fw_card *card, struct fw_request *request,
			   int tcode, int destination, int source,
			   int generation, unsigned long long offset,
			   void *data, size_t length, void *callback_data)
{
	struct snd_motu *motu = callback_data;
	__be32 *buf = (__be32 *)data;

	if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
		fw_send_response(card, request, RCODE_COMPLETE);
		return;
	}

	if (offset != motu->async_handler.offset || length != 4) {
		fw_send_response(card, request, RCODE_ADDRESS_ERROR);
		return;
	}

	scoped_guard(spinlock_irqsave, &motu->lock) {
		motu->msg = be32_to_cpu(*buf);
	}

	fw_send_response(card, request, RCODE_COMPLETE);

	wake_up(&motu->hwdep_wait);
}

int snd_motu_transaction_reregister(struct snd_motu *motu)
{
	struct fw_device *device = fw_parent_device(motu->unit);
	__be32 data;
	int err;

	if (motu->async_handler.callback_data == NULL)
		return -EINVAL;

	/* Register messaging address. Block transaction is not allowed. */
	data = cpu_to_be32((device->card->node_id << 16) |
			   (motu->async_handler.offset >> 32));
	err = snd_motu_transaction_write(motu, ASYNC_ADDR_HI, &data,
					 sizeof(data));
	if (err < 0)
		return err;

Annotation

Implementation Notes