Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * motu-transaction.c - a part of driver for MOTU FireWire series
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "motu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define SND_MOTU_ADDR_BASE	0xfffff0000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define ASYNC_ADDR_HI  0x0b04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define ASYNC_ADDR_LO  0x0b08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 			      size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	int tcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (size % sizeof(__be32) > 0 || size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	if (size == sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		tcode = TCODE_READ_QUADLET_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		tcode = TCODE_READ_BLOCK_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return snd_fw_transaction(motu->unit, tcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 				  SND_MOTU_ADDR_BASE + offset, reg, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			       size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int tcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (size % sizeof(__be32) > 0 || size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (size == sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		tcode = TCODE_WRITE_QUADLET_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		tcode = TCODE_WRITE_BLOCK_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return snd_fw_transaction(motu->unit, tcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				  SND_MOTU_ADDR_BASE + offset, reg, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static void handle_message(struct fw_card *card, struct fw_request *request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			   int tcode, int destination, int source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			   int generation, unsigned long long offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			   void *data, size_t length, void *callback_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct snd_motu *motu = callback_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	__be32 *buf = (__be32 *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		fw_send_response(card, request, RCODE_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return;
^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) 	if (offset != motu->async_handler.offset || length != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		fw_send_response(card, request, RCODE_ADDRESS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	spin_lock_irqsave(&motu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	motu->msg = be32_to_cpu(*buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	spin_unlock_irqrestore(&motu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	fw_send_response(card, request, RCODE_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	wake_up(&motu->hwdep_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) int snd_motu_transaction_reregister(struct snd_motu *motu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct fw_device *device = fw_parent_device(motu->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	__be32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (motu->async_handler.callback_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* Register messaging address. Block transaction is not allowed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	data = cpu_to_be32((device->card->node_id << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			   (motu->async_handler.offset >> 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	err = snd_motu_transaction_write(motu, ASYNC_ADDR_HI, &data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 					 sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	data = cpu_to_be32(motu->async_handler.offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return snd_motu_transaction_write(motu, ASYNC_ADDR_LO, &data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					  sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) int snd_motu_transaction_register(struct snd_motu *motu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	static const struct fw_address_region resp_register_region = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		.start	= 0xffffe0000000ull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		.end	= 0xffffe000ffffull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Perhaps, 4 byte messages are transferred. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	motu->async_handler.length = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	motu->async_handler.address_callback = handle_message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	motu->async_handler.callback_data = motu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	err = fw_core_add_address_handler(&motu->async_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 					  &resp_register_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	err = snd_motu_transaction_reregister(motu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		fw_core_remove_address_handler(&motu->async_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		motu->async_handler.address_callback = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) void snd_motu_transaction_unregister(struct snd_motu *motu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	__be32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (motu->async_handler.address_callback != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		fw_core_remove_address_handler(&motu->async_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	motu->async_handler.address_callback = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* Unregister the address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	data = cpu_to_be32(0x00000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	snd_motu_transaction_write(motu, ASYNC_ADDR_HI, &data, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	snd_motu_transaction_write(motu, ASYNC_ADDR_LO, &data, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }